Skip to content

Standard clj testing #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions notebooks/advanced/customizing_wolframite.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns advanced.customizing-wolframite
(:require [scicloj.kindly.v4.kind :as k]
[wolframite.core :as wl]))
(:require
[scicloj.kindly.v4.kind :as k]
[wolframite.core :as wl]))

(k/md "## Customizing Wolframite

Expand Down
3 changes: 2 additions & 1 deletion notebooks/advanced/index.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(ns advanced.index
(:require [scicloj.kindly.v4.kind :as k]))
(:require
[scicloj.kindly.v4.kind :as k]))

(k/md "See the other pages in this section.")
12 changes: 6 additions & 6 deletions notebooks/advanced/packages.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(ns advanced.packages
"A notebook demonstrating how to import and use Wolfram packages in Wolframite."
(:require
[scicloj.kindly.v4.kind :as k]
[wolframite.core :as wl]
[wolframite.wolfram :as w]))
[scicloj.kindly.v4.kind :as k]
[wolframite.core :as wl]
[wolframite.wolfram :as w]))

(k/md "# Packages

Expand All @@ -29,11 +29,11 @@ additional[y_]:=3*y
(wl/<<! "resources/WolframPackageDemo.wl")

(wl/eval
(WolframPackageDemo/tryIt 10))
(WolframPackageDemo/tryIt 10))
(wl/eval
(WolframPackageDemo/additional 10))
(WolframPackageDemo/additional 10))
(wl/eval
(w/Information WolframPackageDemo/tryIt "Usage"))
(w/Information WolframPackageDemo/tryIt "Usage"))

(k/md "That's it! As you can see, the functions are callable and the documentation is available too.

Expand Down
15 changes: 8 additions & 7 deletions notebooks/clojure_primer/index.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
^:kindly/hide-code
(ns clojure-primer.index
"A very brief introduction to Clojure for a would-be users of Wolframite not familiar with the language"
(:require [scicloj.kindly.v4.kind :as k]
[clojure.math :as math]
[wolframite.core :as wl]
[wolframite.wolfram :as w]))
(:require
[clojure.math :as math]
[scicloj.kindly.v4.kind :as k]
[wolframite.core :as wl]
[wolframite.wolfram :as w]))

(k/md "# Clojure primer {#sec-clojure-primer}

Expand Down Expand Up @@ -132,9 +133,9 @@ that can be evaluated fully on the Clojure side and replaced with the result, be
;; Notice that you may nest Clojure-only expression, which does not depend on the surrounding Wolfram context, inside a Wolframite expression,
;; but you cannot do the opposite, i.e. nest a Wolframite expression inside a Clojure expression:
(try
(wl/eval (+ (w/* 3 (w/Power (+ 1 1) 2))))
(catch Exception e
(str e)))
(wl/eval (+ (w/* 3 (w/Power (+ 1 1) 2))))
(catch Exception e
(str e)))

;; This fails because we are passing a Wolframite expression (a list) to the Clojure `+` function, but it only works with numbers. We'd need to evaluate the expression first:

Expand Down
2 changes: 1 addition & 1 deletion notebooks/differences_from_clojuratica.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns differences-from-clojuratica
"Collecting differences here until we have enough to justify a page in the docs."
(:require
[scicloj.kindly.v4.kind :as k]))
[scicloj.kindly.v4.kind :as k]))

(k/md "Note, separating expression chains from automatic eval was done for efficiency. Previously, all Wolfram expressions were individually evaluated with separate kernel calls and this was considered a performance problem.")
8 changes: 3 additions & 5 deletions notebooks/faq.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
(ns faq
"Anticipated and, potentially literally, frequently asked questions."
(:require
[scicloj.kindly.v4.kind :as k]
[wolframite.core :as wl]
[wolframite.wolfram :as w :refer :all
:exclude [* + - -> / < <= = == > >= fn
Byte Character Integer Number Short String Thread]]))
[scicloj.kindly.v4.kind :as k]
[wolframite.core :as wl]
[wolframite.wolfram :as w :refer :all :exclude [* + - -> / < <= = == > >= Byte Character Integer Number Short String Thread fn]]))

(wl/start!)

Expand Down
22 changes: 9 additions & 13 deletions notebooks/for_developers/demo_analysis_cycling.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
(:require
[clojure.java.io :as io]
[clojure.string :as str]
[scicloj.kindly.v4.kind :as k]
[wolframite.core :as wl]
[wolframite.lib.helpers :as h]
[wolframite.wolfram :as w :refer :all
:exclude [* + - -> / < <= = == > >= fn
Byte Character Integer Number Short String Thread]]
[wolframite.impl.wolfram-syms.intern :as intern]
[scicloj.kindly.v4.kind :as k])
(:import (java.util.zip GZIPInputStream)))
[wolframite.lib.helpers :as h]
[wolframite.wolfram :as w :refer :all :exclude [* + - -> / < <= = == > >= Byte Character Integer Number Short String Thread fn]])
(:import
(java.util.zip GZIPInputStream)))

(k/md "
We introduce you, the motivated Clojure developer, to using the Wolfram programming language as a Clojure library. Following some brief inspiration (why on earth should you do this?), and some getting started notes, we outline a 'real' workflow using the example of analysing data about bike trips.")
Expand Down Expand Up @@ -57,10 +56,10 @@ Thus we will need a more DIY and lower-level approach to getting the data in, le
Sadly, it cannot handle a gzpipped files (as far as I know) so we need to unzip it first:")

(when-not (.exists (io/file "/tmp/huge.csv"))
(let [zip (io/file "docs-buildtime-data/202304_divvy_tripdata_first100k.csv.gz")]
(with-open [zis (GZIPInputStream. (io/input-stream zip))]
(io/copy zis (io/file "/tmp/huge.csv"))))
:extracted)
(let [zip (io/file "docs-buildtime-data/202304_divvy_tripdata_first100k.csv.gz")]
(with-open [zis (GZIPInputStream. (io/input-stream zip))]
(io/copy zis (io/file "/tmp/huge.csv"))))
:extracted)

(k/md "
Now we are ready to read the data in. We will store them into a Wolfram-side var so that we can work with them further.
Expand All @@ -72,7 +71,6 @@ For readability and auto-completion, we will define vars for the names of the Wo
(def rawRows "Wolf var - unparsed data rows" 'rawRows)
(def rows "Wolf var - parsed data rows" 'rows)


(wl/eval (w/do (w/= 'f (w/OpenRead "/tmp/huge.csv"))
(w/= csv (w/ReadList 'f
w/Word
Expand All @@ -83,7 +81,6 @@ For readability and auto-completion, we will define vars for the names of the Wo
;; Let's return only the length instead of all the large data:
(w/Length csv)))


(k/md (str "We leverage the flexibility of [ReadList](" (first (h/help! w/ReadList :links true))
"), instructing it to read \"Words\" separated by `,` (instead of applying the normal word separating characters),
thus reading individual column values. It reads them as records, separated by the given separators (which are the same as the default, shown here for clarity).
Expand Down Expand Up @@ -163,7 +160,6 @@ Let's see how it works:")
(let [header->idx' (zipmap loc-ks (next (range)))]
(w/fn [row] (mapv #(w/Part row (header->idx' %)) col-names))))


;; For me, it took ±0.8s to extract the 2 columns as text and 1.5s to parse them into numbers. With `ToExpression` it would take ±5s.

;; #### Starting positions in a map
Expand Down
5 changes: 3 additions & 2 deletions notebooks/for_developers/index.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
^:kindly/hide-code
(ns for-developers.index
(:require [scicloj.kindly.v4.kind :as k]))
(:require
[scicloj.kindly.v4.kind :as k]))

(k/md "# Wolframite for Clojure developers {#sec-for-developers}

This section is intended for you, a developer familiar with Clojure, who may know little or nothing about Wolfram.

You may decide whether you want to learn a little about Wolfram first in @sec-wolfram-for-clojurians or jump right to
an example analysis of data with Wolfram in @sec-demo-analysis-cycling.")
an example analysis of data with Wolfram in @sec-demo-analysis-cycling.")
32 changes: 15 additions & 17 deletions notebooks/for_developers/wolfram_for_clojurians.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
;; # Brief introduction into Wolfram Language for Clojure developers {#sec-wolfram-for-clojurians}

(ns for-developers.wolfram-for-clojurians
(:require [scicloj.kindly.v4.kind :as k]
[wolframite.core :as wl]
[wolframite.wolfram :as w :refer :all
:exclude [* + - -> / < <= = == > >= fn
Byte Character Integer Number Short String Thread]]))
(:require
[scicloj.kindly.v4.kind :as k]
[wolframite.core :as wl]
[wolframite.wolfram :as w :refer :all :exclude [* + - -> / < <= = == > >= Byte Character Integer Number Short String Thread fn]]))

(wl/start!)

Expand Down Expand Up @@ -56,7 +55,6 @@ may use `#, #1, #2, ...` or `(Slot 1), (Slot 1), (Slot 2), ...` equivalent to Cl
In Wolframite, you'll typically use `w/fn` or leverage the _operator form_ of functions (see @sec-operator-form).
")


(k/md "#### [Lists](https://www.wolfram.com/language/fast-introduction-for-programmers/en/lists/)
")
; A Wolfram List `{1, "hello", 3.14}` becomes a vector in Wolframite: `[1, "hello", 3.14]`.
Expand Down Expand Up @@ -141,21 +139,21 @@ See [Functionals & Operators](https://www.wolfram.com/language/fast-introduction
(k/md "#### Clojure <-> Wolfram
")
^:kindly/hide-code
(k/table {:column-names [:Clojure :Wolfram :Comments],
:row-vectors [["apply" "Apply"]
["comp" "Composition"]
["count" "Length"]
["filter" "Select"]
["nth" "Part" "1-based indexing"]
["map" "Map"]
["partial" "operator form" "(see above)"]
["reduce" "Fold"]
["take" "Part"]]})
(k/table {:column-names [:Clojure :Wolfram :Comments]
,:row-vectors [["apply" "Apply"]
["comp" "Composition"]
["count" "Length"]
["filter" "Select"]
["nth" "Part" "1-based indexing"]
["map" "Map"]
["partial" "operator form" "(see above)"]
["reduce" "Fold"]
["take" "Part"]]})

(k/md "#### Additional resources

Read more in the online booklet [The Wolfram Language: Fast Introduction for Programmers](https://www.wolfram.com/language/fast-introduction-for-programmers/en/),
which we have borrowed heavily from.

The dense one-page [Wolfram Language Syntax](https://reference.wolfram.com/language/guide/Syntax.html) may also be of use, especially when reading Wolfram code.
")
")
32 changes: 15 additions & 17 deletions notebooks/for_scientists/cavity_physics.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
"The second part of Wolframite for scientists. Here, we consider a real physics problem
as a demonstration of how one might use Wolframite in practice."
(:require
[clojure.math :as math]
[scicloj.kindly.v4.kind :as k]
[wolframite.core :as wl]
[wolframite.tools.hiccup :as wh]
[wolframite.wolfram :as w :refer :all
:exclude [* + - -> / < <= = == > >= fn
Byte Character Integer Number Short String Thread]]))
[clojure.math :as math]
[scicloj.kindly.v4.kind :as k]
[wolframite.core :as wl]
[wolframite.tools.hiccup :as wh]
[wolframite.wolfram :as w :refer :all :exclude [* + - -> / < <= = == > >= Byte Character Integer Number Short String Thread fn]]))

(k/md "# Wolframite for scientists II (Cavity physics)

Expand Down Expand Up @@ -119,7 +117,7 @@ At position three, the field undergoes reflection and so now carries an addition
(k/md "Substitution and simplification can then be used to arrive at the transmission and reflection, respectively.")

(def T (-> (x>> (w/* E2 't2)
e4)
e4)
w/>>_<<))
(TeX->> T (w/== 'T))

Expand Down Expand Up @@ -257,17 +255,17 @@ For this, we will define a few utility functions, that also demonstrate Wolfram'

(wl/eval (w/_= 'nums (mapv Efield--transmission-phase
(coordinates
(math/sqrt 50E-6)
(math/sqrt 700E-6)
-0.001
0.001))))
(math/sqrt 50E-6)
(math/sqrt 700E-6)
-0.001
0.001))))

(wh/view
(w/ListPlot3D 'nums
(w/-> PlotRange All)
(w/-> Boxed false)
(w/-> AxesLabel
["Mirror transmission" "Phase" "Intracavity intensity"])))
(w/ListPlot3D 'nums
(w/-> PlotRange All)
(w/-> Boxed false)
(w/-> AxesLabel
["Mirror transmission" "Phase" "Intracavity intensity"])))

(k/md "And there you have it! It turns out that if you get the phase right and you buy high quality mirrors then you can massively amplify the laser light. In fact, if you add a 'gain' material in the middle then such light amplification by the stimulated emission of radiation has a catchier name: it's called a *Laser*!")

Expand Down
12 changes: 5 additions & 7 deletions notebooks/for_scientists/index.clj
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
(ns for-scientists.index
"An introduction to the library, that might even be suitable for physicists."
(:require
[scicloj.kindly.v4.kind :as k]
[wolframite.core :as wl]
[wolframite.impl.wolfram-syms.write-ns :as write]
[wolframite.tools.hiccup :as wh]
[wolframite.wolfram :as w :refer :all
:exclude [* + - -> / < <= = == > >= fn
Byte Character Integer Number Short String Thread]]))
[scicloj.kindly.v4.kind :as k]
[wolframite.core :as wl]
[wolframite.impl.wolfram-syms.write-ns :as write]
[wolframite.tools.hiccup :as wh]
[wolframite.wolfram :as w :refer :all :exclude [* + - -> / < <= = == > >= Byte Character Integer Number Short String Thread fn]]))

(k/md "# Wolframite for scientists I (Introduction) {#sec-scientists}")
(k/md "## Abstract
Expand Down
4 changes: 2 additions & 2 deletions notebooks/gotchas.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns gotchas
[:require
[scicloj.kindly.v4.kind :as k]])
(:require
[scicloj.kindly.v4.kind :as k]))

(k/md "# Gotchas... {#sec-gotchas}
Although we try to avoid such things, sometimes, when you're fighting the host language, it's just not practical to carry over the original conventions. Here we will try to keep an up-to-date list of possible surprises, when coming from Wolfram to Wolframite (that are not easy to 'fix').
Expand Down
6 changes: 3 additions & 3 deletions notebooks/index.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
(ns index
"Entrypoint for the Clay-generated docs -> docs/generated/index.htm"
(:require
[scicloj.kindly.v4.kind :as kind]
[scicloj.kindly.v4.api :as kindly]))
[scicloj.kindly.v4.api :as kindly]
[scicloj.kindly.v4.kind :as kind]))

^:kindly/hide-code
(defmacro slurp-markdown [path]
Expand All @@ -15,4 +15,4 @@
(kind/md (slurp-markdown "./README.md")))

;; ## Further documentation
;; See the book content menu on the left side
;; See the book content menu on the left side
12 changes: 6 additions & 6 deletions notebooks/lowlevel.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
(ns lowlevel
"Documenting operations that are carried out at a low level of abstraction."
(:require
[wolframite.core :as wl]
[wolframite.wolfram :as w]
[wolframite.impl.jlink-instance :as jlink-instance]
[wolframite.base.parse :as parse]
[scicloj.kindly.v4.kind :as k]))
[scicloj.kindly.v4.kind :as k]
[wolframite.base.parse :as parse]
[wolframite.core :as wl]
[wolframite.impl.jlink-instance :as jlink-instance]
[wolframite.wolfram :as w]))

(k/md "# Low level interoperation

Expand All @@ -18,7 +18,7 @@ Although it shouldn't normally be necessary, we can also intern Wolfram function
The standard way of doing this is something like")
(def greetings
(wl/eval
(w/fn [x] (w/StringJoin "Hello, " x "! This is a Mathematica function's output."))))
(w/fn [x] (w/StringJoin "Hello, " x "! This is a Mathematica function's output."))))
(greetings "Stephen")

(k/md "But this can also be done at a lower level, e.g.")
Expand Down
Loading