-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved init_phase and use ordered table in code eval so the order o…
…f the files included matters
- Loading branch information
Showing
9 changed files
with
202 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import nimjl | ||
|
||
Julia.init() # Initialize Julia VM. This should be done once in the lifetime of your program. | ||
proc main() = | ||
Julia.init() # Initialize Julia VM. This should be done once in the lifetime of your program. | ||
|
||
# Calling Julia function from Nim will always return a JlValue | ||
# This JlValue can be "nothing" | ||
# Therefore, Julia function who do not return a value can be discarded | ||
var res = Julia.println("Hello world") | ||
echo res # nothing | ||
# Check that res is actually nothing | ||
if res == JlNothing: | ||
echo "Julia.println returned nothing" | ||
# Calling Julia function from Nim will always return a JlValue | ||
# This JlValue can be "nothing" | ||
# Therefore, Julia function who do not return a value can be discarded | ||
var res = Julia.println("Hello world") | ||
echo res # nothing | ||
# Check that res is actually nothing | ||
if res == JlNothing: | ||
echo "Julia.println returned nothing" | ||
|
||
discard Julia.println("This also works") | ||
discard Julia.println("This also works") | ||
|
||
when isMainModule: | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
import nimjl | ||
import std/math | ||
|
||
jlVmInit() # Initialize Julia VM. This should be done once in the lifetime of your program. | ||
proc main() = | ||
jlVmInit() # Initialize Julia VM. This should be done once in the lifetime of your program. | ||
|
||
var myval = 4.0'f64 | ||
# Call Julia function "sqrt" and convert the result to a float | ||
# This syntax also works to call a function directly from a Julia modfule | ||
var res = JlBase.sqrt(myval).to(float64) | ||
# Echo on JlValue calls println from Julia | ||
echo res # 2.0 | ||
doAssert res == sqrt(myval) | ||
var myval = 4.0'f64 | ||
# Call Julia function "sqrt" and convert the result to a float | ||
# This syntax also works to call a function directly from a Julia modfule | ||
var res = JlBase.sqrt(myval).to(float64) | ||
# Echo on JlValue calls println from Julia | ||
echo res # 2.0 | ||
doAssert res == sqrt(myval) | ||
|
||
when isMainModule: | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
import nimjl | ||
import std/sequtils | ||
|
||
Julia.init() | ||
# Use Module handle | ||
discard JlMain.println(@[1, 2, 3]) | ||
discard Julia.println(toSeq(0..5)) | ||
proc main = | ||
Julia.init() | ||
# Use Module handle | ||
discard JlMain.println(@[1, 2, 3]) | ||
discard Julia.println(toSeq(0..5)) | ||
|
||
let arr = [1.0, 2.0, 3.0].toJlArray() | ||
# You can now use echo to call println for you on Julia type ! | ||
echo jltypeof(arr) | ||
echo arr | ||
let arr = [1.0, 2.0, 3.0].toJlArray() | ||
# You can now use echo to call println for you on Julia type ! | ||
echo jltypeof(arr) | ||
echo arr | ||
|
||
# You can also call proc from the value directly | ||
echo arr.stride(1) | ||
echo arr.strides() | ||
# You can also call proc from the value directly | ||
echo arr.stride(1) | ||
echo arr.strides() | ||
|
||
when isMainModule: | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
import nimjl | ||
|
||
## See https://pkgdocs.julialang.org/dev/api/#Pkg.add for more info | ||
Julia.init(1): | ||
Pkg: | ||
add(name="Polynomials", version="3.0.0") | ||
add(name="LinearAlgebra") | ||
add("DSP") | ||
add(name="Wavelets", version="0.9.4") | ||
proc main() = | ||
## See https://pkgdocs.julialang.org/dev/api/#Pkg.add for more info | ||
Julia.init(1): | ||
Pkg: | ||
add(name="Polynomials", version="3.0.0") | ||
add(name="LinearAlgebra") | ||
add("DSP") | ||
|
||
Julia.useModule("Pkg") | ||
let jlpkg = Julia.getModule("Pkg") | ||
discard jlpkg.status() | ||
|
||
Julia.exit() | ||
|
||
when isMainModule: | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.