Skip to content

Commit 0414994

Browse files
authored
Merge pull request #86 from fremling/master
Added to help about W2Julia
2 parents 93430d7 + dbe8c2b commit 0414994

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,31 @@ julia> W2Mstr(W`b/(c^(a+c))`)
162162
```
163163

164164

165+
166+
167+
## W2Julia - Conversion to Julia structures
168+
W2Julia is designed primarily to convert wolfram structures to Julia structures. This includes conversions of Mathematica lists to Julia vectors and Mathematica associations to Julia dictionaries.
169+
170+
Some examples or tests that will evaluate to true:
171+
172+
```
173+
using Test
174+
@test W2Julia(W`{1,2,3}`) == [1,2,3]
175+
@test W2Julia([1,2,3]) == [1,2,3]
176+
@test W2Julia(W`{1,2,3}`) == [1,2,3]
177+
@test W2Julia(W`{1,a,{1,2}}`) == [1,W"a",[1,2]]
178+
@test W2Julia([.1,W`{1,a,3}`]) == [.1,[1,W"a",3]]
179+
180+
@test W2Julia(Dict( 1 => "A" , "B" => 2)) ==Dict( 1 => "A" , "B" => 2)
181+
182+
@test W2Julia(W`Association["A" -> "B", "C" -> "D"]`) == Dict( "A" => "B" , "C" => "D")
183+
184+
@test W2Julia(W`Association["A" -> {1,a,3}, "B" -> "C"]`) == Dict( "A" => [1,W"a",3] , "B" => "C")
185+
```
186+
187+
W2Julia does not convert expressions to Julia functions, as not all functions will be able to evaluate when WSymbols are present.
188+
189+
165190
## LateX printing in JuPyter Notebooks
166191
Printing in Jupyter notebooks is, by default, done in latex.
167192
This can be turned off with the command `MathLink.set_texOutput(false)`

src/W2Julia.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@
22

33
export W2Julia
44

5+
"""
6+
W2Julia is designed primarily to convert wolfram structures to Julia structures. This includes conversions of Mathematica lists to Julia vectors and Mathematica associations to Julia dictionaries.
7+
8+
Some examples or tests that will evaluate to true:
9+
10+
using Test
11+
@test W2Julia(W`{1,2,3}`) == [1,2,3]
12+
@test W2Julia([1,2,3]) == [1,2,3]
13+
@test W2Julia(W`{1,2,3}`) == [1,2,3]
14+
@test W2Julia(W`{1,a,{1,2}}`) == [1,W"a",[1,2]]
15+
@test W2Julia([.1,W`{1,a,3}`]) == [.1,[1,W"a",3]]
16+
17+
@test W2Julia(Dict( 1 => "A" , "B" => 2)) ==Dict( 1 => "A" , "B" => 2)
18+
19+
20+
@test W2Julia(W`Association["A" -> "B", "C" -> "D"]`) == Dict( "A" => "B" , "C" => "D")
21+
22+
@test W2Julia(W`Association["A" -> {1,a,3}, "B" -> "C"]`) == Dict( "A" => [1,W"a",3] , "B" => "C")
23+
24+
25+
W2Julia does not convert expressions to Julia functions, as not all functions will be able to evaluate when WSymbols are present.
26+
27+
"""
528
W2Julia(X::Vector) = [ W2Julia(x) for x in X]
629
function W2Julia(X::Dict)
730
NewDict = Dict()

test/runtests.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import MathLink: WExpr, WSymbol
66

77
@testset "W2Julia" begin
88
###Test of a simple MathLink to Julia converter. It converts MathLink expressions to the correcsponding Julia constructions
9-
109
@testset "Lists to Lists" begin
1110
@test W2Julia(W`{1,2,3}`) == [1,2,3]
1211
@test W2Julia([1,2,3]) == [1,2,3]
@@ -19,10 +18,14 @@ import MathLink: WExpr, WSymbol
1918
@testset "Association to Dict" begin
2019
@test W2Julia(Dict( 1 => "A" , "B" => 2)) ==Dict( 1 => "A" , "B" => 2)
2120

22-
@test W2Julia(W`Association["team" -> "HOU", "lastName" -> "Ching"]`) == Dict( "team" => "HOU" , "lastName" => "Ching")
21+
@test W2Julia(W`Association["A" -> "B", "C" -> "D"]`) == Dict( "A" => "B" , "C" => "D")
2322
end
2423
@testset "Association and List Dict" begin
25-
@test W2Julia(W`Association["team" -> {1,2,3}, "lastName" -> "Ching"]`) == Dict( "team" => [1,2,3] , "lastName" => "Ching")
24+
@test W2Julia(W`Association["A" -> {1,2,3}, "B" -> "C"]`) == Dict( "A" => [1,2,3] , "B" => "C")
25+
26+
@test W2Julia(W`Association["A" -> {1,a,3}, "B" -> "C"]`) == Dict( "A" => [1,W"a",3] , "B" => "C")
27+
28+
2629
@test W2Julia(W`{1,Association["team" -> {1,2,3}, "lastName" -> "Ching"]}`) == [1,Dict( "team" => [1,2,3] , "lastName" => "Ching")]
2730

2831
end

0 commit comments

Comments
 (0)