Woxi
A Rust-based interpreter for a subset of the Wolfram Language.
Features
The initial focus is to implement a subset of the Wolfram Language so that it can be used for CLI scripting and Jupyter notebooks. For example:
#!/usr/bin/env woxi
(* Print 5 random integers between 1 and 6 *)
Print[RandomInteger[{1, 6}, 5]]
All code examples in this documentation are run using Woxi.
Woxi runs faster than WolframScript as there is no overhead of starting a kernel and verifying its license.
Syntax
Basics
Comments
$ wo '(* This comment is ignored *) 5'
5
$ wo '5 (* This comment is ignored *)'
5
Semicolon
$ wo 'x = 2; x'
2
$ wo 'x = 2; x = x + 5'
7
Set
Assign a value to a variable.
$ wo 'Set[x, 5]'
5
$ wo 'Set[x, 5]; x + 3'
8
Print
Print values to the console.
$ wo 'Print[]'
Null
$ wo 'Print[5]'
5
Null
Basic String Tests
Print
$ wo 'Print["Hello World!"]'
Hello World!
Null
StringLength
$ wo 'StringLength["Hello World!"]'
12
StringTake
$ wo 'StringTake["Hello World!", 5]'
Hello
StringDrop
$ wo 'StringDrop["Hello World!", 6]'
World!
StringJoin
$ wo 'StringJoin["Hello", " ", "World!"]'
Hello World!
StringSplit
$ wo 'StringSplit["Hello World!", " "]'
{Hello, World!}
StringStartsQ
$ wo 'StringStartsQ["Hello World!", "Hello"]'
True
$ wo 'StringStartsQ["Hello World!", "Bye"]'
False
StringEndsQ
$ wo 'StringEndsQ["Hello World!", "World!"]'
True
$ wo 'StringEndsQ["Hello World!", "Moon!"]'
False
Boolean Logic
Equal
Compare values for equality.
$ wo 'Equal[1, 1]'
True
$ wo 'Equal[1, 2]'
False
$ wo 'Equal[1, 1, 1]'
True
==
Check if values are equal to each other.
$ wo '2 == 2'
True
$ wo 'x = 2; x == 2'
True
$ wo '2 == 3'
False
Unequal
Compare values for inequality.
$ wo 'Unequal[1, 1]'
False
$ wo 'Unequal[1, 2]'
True
$ wo 'Unequal[1, 1, 1]'
False
!=
Check if values are not equal to each other.
$ wo '2 != 2'
False
$ wo 'x = 2; x != 2'
False
$ wo '2 != 3'
True
Greater
Check if values are greater than each other.
$ wo 'Greater[2, 1]'
True
$ wo 'Greater[1, 2]'
False
$ wo 'Greater[1, 1]'
False
$ wo 'Greater[1, 2, 3]'
False
$ wo 'Greater[3, 2, 1]'
True
>
Check if values are greater than each other.
$ wo '2 > 1'
True
$ wo '1 > 2'
False
Less
Check if values are less than each other.
$ wo 'Less[1, 2]'
True
$ wo 'Less[2, 1]'
False
$ wo 'Less[1, 1]'
False
$ wo 'Less[1, 2, 3]'
True
$ wo 'Less[3, 2, 1]'
False
<
Check if values are greater than each other.
$ wo '1 < 2'
True
$ wo '2 < 1'
False
GreaterEqual
Check if values are greater than or equal to each other.
$ wo 'GreaterEqual[2, 1]'
True
$ wo 'GreaterEqual[1, 2]'
False
$ wo 'GreaterEqual[1, 1]'
True
$ wo 'GreaterEqual[1, 2, 3]'
False
$ wo 'GreaterEqual[3, 2, 1]'
True
>=
$ wo '2 >= 1'
True
$ wo '1 >= 2'
False
LessEqual
Check if values are less than or equal to each other.
$ wo 'LessEqual[1, 2]'
True
$ wo 'LessEqual[2, 1]'
False
$ wo 'LessEqual[1, 1]'
True
$ wo 'LessEqual[1, 2, 3]'
True
$ wo 'LessEqual[3, 2, 1]'
False
<=
$ wo '1 <= 2'
True
$ wo '2 <= 2'
True
$ wo '2 <= 1'
False
Multiple comparisons
$ wo 'x = 1; 0 <= x <= 2'
True
$ wo 'x = 1; 0 < x < 2'
True
$ wo 'x = 1; 0 > x < 2'
False
$ wo 'x = 1; 0 < x > 2'
False
And
Logical AND operation.
$ wo 'And[True, True]'
True
$ wo 'And[True, False]'
False
$ wo 'And[False, True]'
False
$ wo 'And[False, False]'
False
$ wo 'And[True, True, True]'
True
$ wo 'And[True, False, True]'
False
Or
Logical OR operation.
$ wo 'Or[True, True]'
True
$ wo 'Or[True, False]'
True
$ wo 'Or[False, True]'
True
$ wo 'Or[False, False]'
False
$ wo 'Or[True, True, True]'
True
$ wo 'Or[True, False, True]'
True
Not
Logical NOT operation.
$ wo 'Not[True]'
False
$ wo 'Not[False]'
True
$ wo 'Not[True, True]'
Not::argx: Not called with 2 arguments; 1 argument is expected.
Not[True, True]
Xor
Logical XOR operation.
$ wo 'Xor[True, True]'
False
$ wo 'Xor[True, False]'
True
$ wo 'Xor[False, True]'
True
$ wo 'Xor[False, False]'
False
$ wo 'Xor[True, True, True]'
True
$ wo 'Xor[True, True, False]'
False
If
Conditional operation.
$ wo 'If[True, 1]'
1
$ wo 'If[False, 1]'
Null
$ wo 'If[True, 1, 0]'
1
$ wo 'If[False, 1, 0]'
0
$ wo 'If["x", 1, 0, 2]'
2
$ wo 'If[True, 1, 0, 2, 3]'
If::argb: If called with 5 arguments; between 2 and 4 arguments are expected.
If[True, 1, 0, 2, 3]
IntegerQ
Check if a value is an integer.
$ wo 'IntegerQ[5]'
True
$ wo 'IntegerQ[0]'
True
$ wo 'IntegerQ[-7]'
True
$ wo 'IntegerQ[3.0]'
True
$ wo 'IntegerQ[3.5]'
False
$ wo 'IntegerQ[1.2]'
False
$ wo 'IntegerQ[-0.5]'
False
$ wo 'IntegerQ[0.0]'
True
$ wo 'IntegerQ[a]'
False
EvenQ
Check if a number is even.
$ wo 'EvenQ[2]'
True
$ wo 'EvenQ[3]'
False
$ wo 'EvenQ[0]'
True
$ wo 'EvenQ[-4]'
False
$ wo 'EvenQ[-2]'
False
$ wo 'EvenQ[100]'
True
$ wo 'EvenQ[1.5]'
False
OddQ
Check if a number is odd.
$ wo 'OddQ[3]'
True
$ wo 'OddQ[2]'
False
$ wo 'OddQ[0]'
False
$ wo 'OddQ[-3]'
True
$ wo 'OddQ[-4]'
True
$ wo 'OddQ[101]'
True
$ wo 'OddQ[2.5]'
False
AllTrue
Check if all elements in a list satisfy a condition.
$ wo 'AllTrue[{2, 4, 6}, EvenQ]'
True
$ wo 'AllTrue[{2, 3, 4}, EvenQ]'
False
$ wo 'AllTrue[{1, 3, 6}, 1 <= # <= 6 &]'
True
Basic Math Tests
Plus
Add numbers.
$ wo 'Plus[1, 2]'
3
$ wo 'Plus[1, 2, 3]'
6
$ wo 'Plus[-1, -2]'
-3
+
$ wo '1+2'
3
$ wo '8 + (-5)'
3
Minus
Make numbers negative.
$ wo 'Minus[5]'
-5
$ wo 'Minus[5, 2]'
Minus::argx: Minus called with 2 arguments; 1 argument is expected.
5 − 2
Subtract
Subtract numbers.
$ wo 'Subtract[5, 2]'
3
-
$ wo '5-2'
3
Times
Multiply numbers.
$ wo 'Times[2, 3]'
6
$ wo 'Times[2, 3, 4]'
24
$ wo 'Times[-2, 3]'
-6
*
$ wo '2*2'
4
$ wo '2 * (-2)'
-4
Divide
Divide numbers.
$ wo 'Divide[6, 2]'
3
$ wo 'Divide[6, 2, 3]'
Divide::argrx: Divide called with 3 arguments; 2 arguments are expected.
Divide[6, 2, 3]
Sign
Returns the sign of a number.
$ wo 'Sign[5]'
1
$ wo 'Sign[0]'
0
$ wo 'Sign[-7]'
-1
Prime
Returns the nth prime number.
$ wo 'Prime[5]'
11
Abs
Returns the absolute value of a number.
$ wo 'Abs[-5]'
5
$ wo 'Abs[5]'
5
$ wo 'Abs[0]'
0
Floor
Rounds down to the nearest integer.
$ wo 'Floor[3.7]'
3
$ wo 'Floor[-3.7]'
-4
$ wo 'Floor[3.2]'
3
$ wo 'Floor[0]'
0
$ wo 'Floor[-0]'
0
$ wo 'Floor[0.5]'
0
$ wo 'Floor[-0.5]'
-1
Ceiling
Rounds up to the nearest integer.
$ wo 'Ceiling[3.2]'
4
$ wo 'Ceiling[-3.2]'
-3
$ wo 'Ceiling[3.7]'
4
$ wo 'Ceiling[0]'
0
$ wo 'Ceiling[-0]'
0
$ wo 'Ceiling[0.5]'
1
$ wo 'Ceiling[-0.5]'
0
Round
Rounds to the nearest integer.
$ wo 'Round[3.5]'
4
$ wo 'Round[3.4]'
3
$ wo 'Round[-3.5]'
-4
$ wo 'Round[-3.4]'
-3
$ wo 'Round[0.5]'
0
$ wo 'Round[-0.5]'
0
$ wo 'Round[0]'
0
$ wo 'Round[-0]'
0
Sqrt
Returns the square root of a number.
$ wo 'Sqrt[16]'
4
$ wo 'Sqrt[0]'
0
Mod
Returns the remainder when dividing the first argument by the second.
$ wo 'Mod[10, 3]'
1
$ wo 'Mod[7, 4]'
3
$ wo 'Mod[15, 5]'
0
$ wo 'Mod[8, 3]'
2
$ wo 'Mod[-1, 3]'
2
$ wo 'Mod[-5, 3]'
1
$ wo 'Mod[10, -3]'
-2
$ wo 'Mod[7.5, 2]'
1.5
$ wo 'Mod[0, 5]'
0
Max
Returns the maximum value from a set of arguments or a list.
Multiple arguments
$ wo 'Max[1, 5, 3]'
5
$ wo 'Max[1, 2]'
2
$ wo 'Max[-5, -2, -8]'
-2
$ wo 'Max[3.14, 2.71, 3.5]'
3.5
$ wo 'Max[1, 2.5, 3]'
3
Single list argument
$ wo 'Max[{1, 5, 3}]'
5
$ wo 'Max[{-10, -5, -20}]'
-5
$ wo 'Max[{3.14, 2.71, 3.5}]'
3.5
Single value
$ wo 'Max[42]'
42
$ wo 'Max[-7]'
-7
Empty list
$ wo 'Max[{}]'
-Infinity
With expressions
$ wo 'Max[2 + 3, 4 * 2, 10 - 1]'
9
$ wo 'Max[{1 + 1, 2 * 2, 3 - 1}]'
4
Min
Returns the minimum value from a set of arguments or a list.
Multiple arguments
$ wo 'Min[1, 5, 3]'
1
$ wo 'Min[1, 2]'
1
$ wo 'Min[-5, -2, -8]'
-8
$ wo 'Min[3.14, 2.71, 3.5]'
2.71
$ wo 'Min[1, 2.5, 3]'
1
Single list argument
$ wo 'Min[{1, 5, 3}]'
1
$ wo 'Min[{-10, -5, -20}]'
-20
$ wo 'Min[{3.14, 2.71, 3.5}]'
2.71
Single value
$ wo 'Min[42]'
42
$ wo 'Min[-7]'
-7
Empty list
$ wo 'Min[{}]'
Infinity
With expressions
$ wo 'Min[2 + 3, 4 * 2, 10 - 1]'
5
$ wo 'Min[{1 + 1, 2 * 2, 3 - 1}]'
2
Sin
Returns the sine of an angle in radians.
$ wo 'Sin[Pi/2]'
1
NumberQ
Returns True if expr is a number, and False otherwise.
$ wo 'NumberQ[2]'
True
MemberQ
Checks if an element is in a list.
$ wo 'MemberQ[{1, 2}, 2]'
True
$ wo 'MemberQ[{1, 2}, 3]'
False
RandomInteger
RandomInteger[]
Randomly gives 0 or 1.
$ wo 'MemberQ[{0, 1}, RandomInteger[]]'
True
RandomInteger[{1, 6}]
Randomly gives a number between 1 and 6.
$ wo 'MemberQ[{1, 2, 3, 4, 5, 6}, RandomInteger[{1, 6}]]'
True
RandomInteger[{1, 6}, 50]
Randomly gives 50 numbers between 1 and 6.
$ wo 'AllTrue[RandomInteger[{1, 6}, 50], 1 <= # <= 6 &]'
True
Power
Power[2, 3]
2 raised to the power of 3 equals 8.
$ wo 'Power[2, 3]'
8
Power[5, 0]
Any number raised to the power of 0 equals 1.
$ wo 'Power[5, 0]'
1
Power[2, -1]
2 raised to the power of -1 equals 0.5 (1/2).
$ wo 'Power[2, -1]'
0.5
Power[4, 0.5]
4 raised to the power of 0.5 equals 2 (square root).
$ wo 'Power[4, 0.5]'
2
Power[10, 2]
10 raised to the power of 2 equals 100.
$ wo 'Power[10, 2]'
100
Power[-2, 3]
-2 raised to the power of 3 equals -8.
$ wo 'Power[-2, 3]'
-8
Power[-2, 2]
-2 raised to the power of 2 equals 4.
$ wo 'Power[-2, 2]'
4
Power[27, 1/3]
27 raised to the power of 1/3 equals approximately 3 (cube root).
$ wo 'Power[27, 1/3]'
2.9999999997
Power[1.5, 2.5]
1.5 raised to the power of 2.5 equals approximately 2.756.
$ wo 'Power[1.5, 2.5]'
2.7556759606
Factorial
Factorial[0]
The factorial of 0 is 1 by definition.
$ wo 'Factorial[0]'
1
Factorial[1]
The factorial of 1 is 1.
$ wo 'Factorial[1]'
1
Factorial[5]
The factorial of 5 is 120 (5! = 5 × 4 × 3 × 2 × 1).
$ wo 'Factorial[5]'
120
Factorial[10]
The factorial of 10 is 3628800.
$ wo 'Factorial[10]'
3628800
Factorial[3]
The factorial of 3 is 6 (3! = 3 × 2 × 1).
$ wo 'Factorial[3]'
6
Factorial[7]
The factorial of 7 is 5040.
$ wo 'Factorial[7]'
5040
Factorial[12]
The factorial of 12 is 479001600.
$ wo 'Factorial[12]'
479001600
Factorial[2]
The factorial of 2 is 2.
$ wo 'Factorial[2]'
2
Factorial[4]
The factorial of 4 is 24 (4! = 4 × 3 × 2 × 1).
$ wo 'Factorial[4]'
24
GCD
GCD[12, 8]
The GCD of 12 and 8 is 4.
$ wo 'GCD[12, 8]'
4
GCD[48, 18]
The GCD of 48 and 18 is 6.
$ wo 'GCD[48, 18]'
6
GCD[100, 50]
The GCD of 100 and 50 is 50.
$ wo 'GCD[100, 50]'
50
GCD[17, 19]
The GCD of 17 and 19 is 1 (coprime numbers).
$ wo 'GCD[17, 19]'
1
GCD[0, 5]
The GCD of 0 and any number n is |n|.
$ wo 'GCD[0, 5]'
5
GCD[15, 25, 35]
The GCD of 15, 25, and 35 is 5.
$ wo 'GCD[15, 25, 35]'
5
GCD[24, 36, 60]
The GCD of 24, 36, and 60 is 12.
$ wo 'GCD[24, 36, 60]'
12
GCD[-12, 8]
The GCD works with negative numbers (GCD of -12 and 8 is 4).
$ wo 'GCD[-12, 8]'
4
GCD[21, 14]
The GCD of 21 and 14 is 7.
$ wo 'GCD[21, 14]'
7
List operations tests
Length
Returns the number of elements in a list.
$ wo 'Length[{7, 2, 4}]'
3
First
Returns the first element of a list.
$ wo 'First[{7, 2, 4}]'
7
Last
Returns the last element of a list.
$ wo 'Last[{7, 2, 4}]'
4
Rest
Returns the list without its first element.
$ wo 'Rest[{7, 2, 4}]'
{2, 4}
Most
Returns the list without its last element.
$ wo 'Most[{7, 2, 4}]'
{7, 2}
Take
Returns the first n elements of a list.
$ wo 'Take[{7, 2, 4}, 2]'
{7, 2}
Part
Returns the nth element of a list.
$ wo 'Part[{7, 6, 4}, 2]'
6
Drop
Returns the list without its first n elements.
$ wo 'Drop[{7, 2, 4}, 2]'
{4}
Append
Adds an element to the end of a list.
$ wo 'Append[{7, 2, 4}, 5]'
{7, 2, 4, 5}
Prepend
Adds an element to the beginning of a list.
$ wo 'Prepend[{7, 2, 4}, 5]'
{5, 7, 2, 4}
Reverse
Returns a list with elements in reverse order.
$ wo 'Reverse[{1, 2, 3}]'
{3, 2, 1}
$ wo 'Reverse[{7, 2, 4}]'
{4, 2, 7}
$ wo 'Reverse[{1}]'
{1}
$ wo 'Reverse[{}]'
{}
$ wo 'Reverse[{a, b, c, d}]'
{d, c, b, a}
$ wo 'Reverse[{-5, 3.14, 0, 42}]'
{42, 0, 3.14, -5}
Take
Returns the first n elements of a list.
$ wo 'Take[{1, 2, 3, 4, 5}, 3]'
{1, 2, 3}
$ wo 'Take[{1, 2, 3, 4, 5}, 1]'
{1}
$ wo 'Take[{1, 2, 3}, 5]'
{1, 2, 3}
$ wo 'Take[{a, b, c, d}, 2]'
{a, b}
$ wo 'Take[{1.5, 2.5, 3.5, 4.5}, 2]'
{1.5, 2.5}
$ wo 'Take[{10, 20, 30, 40}, 4]'
{10, 20, 30, 40}
$ wo 'Take[{1, 2, 3, 4, 5}, 5]'
{1, 2, 3, 4, 5}
Rest
Returns the list without its first element.
$ wo 'Rest[{1, 2, 3}]'
{2, 3}
$ wo 'Rest[{5, 10, 15, 20}]'
{10, 15, 20}
$ wo 'Rest[{a, b, c}]'
{b, c}
$ wo 'Rest[{42}]'
{}
$ wo 'Rest[{-5, 0, 5}]'
{0, 5}
$ wo 'Rest[{1.5, 2.5, 3.5}]'
{2.5, 3.5}
Range
Generates a sequence of numbers.
Range[n]
Generates {1, 2, ..., n}.
$ wo 'Range[5]'
{1, 2, 3, 4, 5}
$ wo 'Range[1]'
{1}
$ wo 'Range[0]'
{}
$ wo 'Range[10]'
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Range[min, max]
Generates {min, min+1, ..., max}.
$ wo 'Range[3, 7]'
{3, 4, 5, 6, 7}
$ wo 'Range[0, 5]'
{0, 1, 2, 3, 4, 5}
$ wo 'Range[-3, 2]'
{-3, -2, -1, 0, 1, 2}
$ wo 'Range[5, 5]'
{5}
Range[min, max, step]
Generates {min, min+step, ..., max}.
$ wo 'Range[1, 10, 2]'
{1, 3, 5, 7, 9}
$ wo 'Range[0, 20, 5]'
{0, 5, 10, 15, 20}
$ wo 'Range[10, 1, -1]'
{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}
$ wo 'Range[5, -5, -2]'
{5, 3, 1, -1, -3, -5}
$ wo 'Range[1, 10, 3]'
{1, 4, 7, 10}
Join
Concatenates multiple lists together.
$ wo 'Join[{a, b}, {c, d}]'
{a, b, c, d}
$ wo 'Join[{1, 2}, {3, 4}, {5, 6}]'
{1, 2, 3, 4, 5, 6}
$ wo 'Join[{1}]'
{1}
$ wo 'Join[{}]'
{}
$ wo 'Join[{}, {1, 2}]'
{1, 2}
$ wo 'Join[{1, 2}, {}]'
{1, 2}
$ wo 'Join[{a}, {b}, {c}, {d}]'
{a, b, c, d}
$ wo 'Join[{1, 2}, {3.14, 2.71}]'
{1, 2, 3.14, 2.71}
Sort
Sorts a list in ascending order.
$ wo 'Sort[{3, 1, 4, 1, 5, 9, 2, 6}]'
{1, 1, 2, 3, 4, 5, 6, 9}
$ wo 'Sort[{5, 2, 8, 1, 9}]'
{1, 2, 5, 8, 9}
$ wo 'Sort[{1}]'
{1}
$ wo 'Sort[{}]'
{}
$ wo 'Sort[{-5, 3, 0, -2, 7}]'
{-5, -2, 0, 3, 7}
$ wo 'Sort[{3.14, 2.71, 1.41, 2.23}]'
{1.41, 2.23, 2.71, 3.14}
$ wo 'Sort[{10, 5, 15, 5, 20}]'
{5, 5, 10, 15, 20}
$ wo 'Sort[{-10, -5, -15, -20}]'
{-20, -15, -10, -5}
Map
Applies a function to each element of a list.
$ wo 'Map[Sign, {-6, 0, 2, 5}]'
{-1, 0, 1, 1}
Select
Picks elements of a list that satisfy a criterion.
$ wo 'Select[{1, 2, 3, 4}, EvenQ]'
{2, 4}
Flatten
Flattens nested lists.
$ wo 'Flatten[{{1}, {2, 3}}]'
{1, 2, 3}
Total
Sums the elements of a list.
$ wo 'Total[{1, 2, 3}]'
6
Mean
Calculates the arithmetic mean (average) of a list.
$ wo 'Mean[{1, 2, 3, 4, 5}]'
3
$ wo 'Mean[{10, 20, 30}]'
20
$ wo 'Mean[{1, 2, 3}]'
2
$ wo 'Mean[{5}]'
5
$ wo 'Mean[{-5, 5}]'
0
$ wo 'Mean[{1.5, 2.5, 3.5}]'
2.5
$ wo 'Mean[{0, 0, 0, 10}]'
2.5
$ wo 'Mean[{-10, -5, 0, 5, 10}]'
0
Median
Returns the median value of a list.
$ wo 'Median[{1, 2, 3, 4, 5}]'
3
$ wo 'Median[{1, 2, 3, 4}]'
2.5
$ wo 'Median[{5, 1, 3, 2, 4}]'
3
$ wo 'Median[{10}]'
10
$ wo 'Median[{1, 10}]'
5.5
$ wo 'Median[{1, 3, 5, 7, 9}]'
5
$ wo 'Median[{-5, 0, 5}]'
0
$ wo 'Median[{1.5, 2.5, 3.5, 4.5}]'
3
$ wo 'Median[{100, 1, 50}]'
50
Product
Multiplies all the elements of a list together.
$ wo 'Product[{1, 2, 3}]'
6
$ wo 'Product[{2, 3, 4}]'
24
$ wo 'Product[{1, 2, 3, 4, 5}]'
120
$ wo 'Product[{5}]'
5
$ wo 'Product[{}]'
1
$ wo 'Product[{-2, 3}]'
-6
$ wo 'Product[{-2, -3}]'
6
$ wo 'Product[{2, 0, 5}]'
0
$ wo 'Product[{1.5, 2}]'
3
$ wo 'Product[{2, 2.5}]'
5
Accumulate
Returns the cumulative sums of a list.
$ wo 'Accumulate[{1, 2, 3}]'
{1, 3, 6}
$ wo 'Accumulate[{1, 2, 3, 4, 5}]'
{1, 3, 6, 10, 15}
$ wo 'Accumulate[{5}]'
{5}
$ wo 'Accumulate[{}]'
{}
$ wo 'Accumulate[{-1, 2, -3}]'
{-1, 1, -2}
$ wo 'Accumulate[{10, -5, 3}]'
{10, 5, 8}
$ wo 'Accumulate[{1.5, 2.5}]'
{1.5, 4}
$ wo 'Accumulate[{0, 0, 1}]'
{0, 0, 1}
$ wo 'Accumulate[{-5, -10, -15}]'
{-5, -15, -30}
Differences
Returns successive differences between consecutive elements.
$ wo 'Differences[{1, 3, 6, 10}]'
{2, 3, 4}
$ wo 'Differences[{1, 2, 3, 4, 5}]'
{1, 1, 1, 1}
$ wo 'Differences[{10, 5, 3}]'
{-5, -2}
$ wo 'Differences[{5}]'
{}
$ wo 'Differences[{}]'
{}
$ wo 'Differences[{0, 1, 0, 1}]'
{1, -1, 1}
$ wo 'Differences[{1.5, 3, 5.5}]'
{1.5, 2.5}
$ wo 'Differences[{-5, -3, 0, 5}]'
{2, 3, 5}
$ wo 'Differences[{100, 90, 80}]'
{-10, -10}
Cases
Extracts elements from an expression that match a pattern.
$ wo 'Cases[{a, b, a}, a]'
{a, a}
DeleteCases
Removes elements from an expression that match a pattern.
$ wo 'DeleteCases[{a, b, a}, a]'
{b}
MapThread
Applies a function to corresponding elements in several lists.
$ wo 'MapThread[Plus, {{1, 2}, {3, 4}}]'
{4, 6}
Partition
Breaks a list into smaller sublists.
$ wo 'Partition[{1, 2, 3, 4}, 2]'
{{1, 2}, {3, 4}}
SortBy
Sorts elements of a list according to a function.
$ wo 'SortBy[{3, 1, 2}, # &]'
{1, 2, 3}
GroupBy
Groups elements of a list according to a function.
$ wo 'GroupBy[{{a, b}, {a, c}, {b, c}}, First]'
> /<|a -> {{a, b}, {a, c}}, b -> {{b, c}}|>/
Accumulate
Returns the cumulative sums of a list.
$ wo 'Accumulate[{1, 2, 3}]'
{1, 3, 6}
Array
Constructs an array using a function to generate elements.
$ wo 'Array[#^2 &, 3]'
{1, 4, 9}
Functions
Nested Function Application
$ wo 'Plus[Divide[6, 2], Abs[-5]]'
8
Anonymous Identity Function
$ wo '#&[1]'
1
Function Application
$ wo '#^2 &[{1, 2, 3}]'
{1, 4, 9}
/@ (Map)
Apply a function to each element of a list.
$ wo 'Sign /@ {7, -2, 0, -5}'
{1, -1, 0, -1}
$ wo '#^2& /@ {1, 2, 3}'
{1, 4, 9}
$ wo 'Sin@(Pi/2)'
1
$ wo '(Pi/2) // Sin'
1
Define And Use A Function
$ wo 'Double[x_] := x * 2; Double[5]'
10
$ wo 'Double[x_] := x * 2; Double[Sin[Pi/2]]'
2
$ wo 'Double[x_] := x * 2; Double @ Sin @ (Pi/2)'
2
$ wo 'Double[x_] := x * 2; (Pi/2) // Sin // Double'
2
Apply (@@)
Replaces the head of an expression with a function.
$ wo 'f @@ {1, 2, 3}'
f[1, 2, 3]
Fold
Applies a function cumulatively to elements of a list, starting with an initial value.
$ wo 'Fold[Plus, 0, {1, 2, 3}]'
6
FoldList
Like Fold, but returns a list of intermediate results.
$ wo 'FoldList[Plus, 0, {1, 2, 3}]'
{0, 1, 3, 6}
Nest
Applies a function repeatedly to an expression.
$ wo 'Nest[f, x, 3]'
f[f[f[x]]]
NestList
Like Nest, but returns a list of intermediate results.
$ wo 'NestList[f, x, 3]'
{x, f[x], f[f[x]], f[f[f[x]]]}
DateString
$ wo 'StringStartsQ[DateString[Now, "ISODateTime"], "2025-"]'
True
Associations
$ wo '<|"Green" -> 2, "Red" -> 1|>'
<|Green -> 2, Red -> 1|>
$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>'
<|Green -> 2, Red -> 1|>
Access values in associations
$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; myHash[["Green"]]'
2
$ wo 'myHash = <|1 -> "Red", 2 -> "Green"|>; myHash[[1]]'
Red
$ wo 'assoc = <|"a" -> True, "b" -> False|>; assoc[["b"]]'
False
Update Values
$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; myHash[["Green"]] = 5; myHash'
<|Green -> 5, Red -> 1|>
Add Values
$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; myHash[["Puce"]] = 3.5; myHash'
<|Green -> 2, Red -> 1, Puce -> 3.5|>
KeyExistsQ
$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; KeyExistsQ[myHash, "Red"]'
True
KeyDropFrom
$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; KeyDropFrom[myHash, "Green"]'
<|Red -> 1|>
Keys
$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; Keys[myHash]'
{Green, Red}
Values
$ wo 'myHash = <|"Green" -> 2, "Red" -> 1|>; Values[myHash]'
{2, 1}
Nested access
$ wo 'assoc = <|"outer" -> <|"inner" -> 8|>|>; assoc["outer", "inner"]'
8
Map
$ wo 'assoc = <|"a" -> 2, "b" -> 3|>; Map[#^2&, assoc]'
<|a -> 4, b -> 9|>
CLI
$ "$TESTDIR/../scripts/hello_world.wls"
Hello World!
Module
$ wo 'Module[{count}, count=0; (IncCount[] := ++count); (DecCount[] := --count)]'
$ wo 'count'
$ wo 'IncCount[]'
1
$ wo 'IncCount[]'
2
$ wo 'DecCount[]'
1
$ wo 'count'
Symbolic Computing
$ wo 'cow + 5'
5 + cow
$ wo 'cow + 5 + 10'
15 + cow
$ wo '%'
15 + cow
$ wo '% - cow'
15
$ wo 'moo = cow + 5'
cow + 5
Replacement rules tests
ReplaceAll (/.)
Replaces parts of an expression according to rules.
$ wo '{a, b} /. a -> x'
{x, b}
ReplaceRepeated (//.)
Repeatedly applies transformation rules until no more changes occur.
$ wo 'ReplaceRepeated[f[2] -> 2][f[f[f[f[2]]]]]'
2
$ wo 'f[f[f[f[2]]]] //. f[2] -> 2'
2
Jupyter
You can also use Woxi in Jupyter notebooks. Install the kernel with:
woxi install-kernel
Then start the Jupyter server:
cd examples && jupyter lab
Resources
Related
- cas3 - Minimal implementation of a Mathematica kernel in Rust.
- CodeParser - Parse Wolfram Language as AST or CST.
- IWolfram - A Jupyter kernel for Wolfram Mathematica
- Lislitica - Classic syntax for Wolfram Language
- Mastika - Rust-based implementation of Wolfram Mathematica.
- MMA Clone - Simple Wolfram Language clone in Haskell.
- Sledgehammer - A code-golf language written in Mathematica.
- TS Wolfram - Toy Wolfram Language interpreter in TypeScript.
- WLJS - Web frontend for Wolfram Language
- Wolfram JS Frontend - Open-source notebook interface for Wolfram Language.
- Wolfram Parser - Wolfram Language parser in Rust.
- wolfram-ast - A Wolfram Language parser written in pure Rust.
- wolfram-exchange - Wolfram exchange format with Rust.
- wolfram-expr - Representing Wolfram Language expressions in Rust.
- Wolfram-Language-Parser - Wolfram Language parser in Java.
- Wolframite - Interface between Clojure and Wolfram Language
- WolframLanguageForJupyter - Wolfram Language kernel for Jupyter notebooks