12 Packages
ns advanced.packages
("A notebook demonstrating how to import and use Wolfram packages in Wolframite."
:require
(:as k]
[scicloj.kindly.v4.kind :as wl]
[wolframite.core :as w])) [wolframite.wolfram
Working with packages has never been easier! Following the Wolfram symbol convention, we introduce Wolframite’s version of <<
, a.k.a. Get
, to both load the given file (*.wl
or *.m
) into the working kernel and to attach the Wolfram context’s symbols (including functions) to a Clojure namespace. The name of the namespace defaults to the context’s name, but you can also define a custom name, passed in as a Clojure symbol.
The functions inside the Wolfram package can then be used just like any other Wolfram functions.
For example, try loading WolframPackageDemo.wl
and running the two functions defined inside:
tryIt[x_] :=
Module[{y},
x^3
]
and
additional[y_]:=3*y
.
(wl/restart!)
:status :ok, :wolfram-version 14.1, :started? true} {
"resources/WolframPackageDemo.wl") (wl/<<!
WolframPackageDemo
(wl/eval10)) (WolframPackageDemo/tryIt
1000
(wl/eval10)) (WolframPackageDemo/additional
30
(wl/eval"Usage")) (w/Information WolframPackageDemo/tryIt
"Used for testing Wolframite."
That’s it! As you can see, the functions are callable and the documentation is available too.
If you want to change the context name, e.g. to make it shorter, then this is also simple. In general, we allow for the package name and context name to be different, so the full call is (... path.wl context alias)
, i.e.
"resources/WolframPackageDemo.wl" "WolframPackageDemo" 'pck) (wl/<<!
pck
10)) (wl/eval (pck/tryIt
1000
"Usage")) (wl/eval (w/Information pck/additional
"Another function in the test package."
And so, you have the whole power of Wolfram packages at your fingertips. And to be honest, this is actually easier to work with than using Wolfram’s contexts directly. Clojure does namespaces well.
source: notebooks/advanced/packages.clj