JSASL is a dialect of the St. Andrews Static Language. It is a turing complete, functional language with 5 basic primitive types: numbers, strings, booleans, pairs and nil. The code is parsed, tokenized, checked for grammar errors and than translated into a graph, which is subsequently reduced and lazily evaluated.
+
, -
, *
and /
(div, not floating point division)()
.""
that can be concatened using +
.and
, or
and not
. Numbers can be compared with =
, ~=
, <
, >
, <=
and >=
. Strings and booleans also support =
and ~=
.else
branch must be present..
. They consist of the keyword def
, a name for the definition and the assignment operator =
def
, variables can be locally defined by using where
. In a where
block, definitions are separated by ;
. Local where
variables override global variables.Lists are linked lists, where every node (a pair) consist of a value and a pointer to its successor. Lists can be defined by square brackets.
A list is terminated by its last node pointing to nil
as its successor. Instead of creating this structure implicitly by using the notation described above, lists can also be defined explicitly with the cons operator :
.
Note how, in the code above, the last pair points to nil
as its last element. The code above can be best understood by reading it as 1:(2:(3:(4:(5:(6:nil)))))
.
The head element (the first element of a pair) can be retrieved via the built-in hd
function. The rest of the list (the second element of a pair) can be retrieved via the built-in tl
function.
Lists are evaluated lazily. This means that you can define lists by defining a pair where the second pair is a function constructing another pair. List elements can than be accessed without evaluating the whole list beforehand. More specifically, this means that you can define lists with infinite length, like the list of all natural numbers starting at n
.