Cons & Lists
(cons a b)
creates a pair (conscell)
(a . b)
.

(fst c)
can be used to extract the first element, 
(rst c)
for the second element. 
(setfst! c v)
sets the first element of pairc
tov

(setrst! c v)
sets the second element of pairc
tov
Combinations of
fst
and
rst
are available for up to four levels of
nesting, e.g.
(rrfrst c)
can be used instead of
(rst (rst (fst (rst
c))))
.
A
list
is made up of nested conscells where the
rst
of the last
one is
nil
.

(list a b c)
creates a list(cons a (cons b (cons c nil)))

(length l)
returns the length of listl

(reverse l)

(range from to)
generates a list of ascending numbers(from from+1 ... to)

(any? pred lst)
returns#t
if(pred e)
is true for any elemente
oflst

(all? pred lst)

(none? pred lst)

TODO
(count pred lst)

TODO
(map f lst)

TODO
(flatmap f lst)

TODO
(select f lst)

TODO
(reject f lst)

TODO
(transpose lst)

TODO
(reduce f acc lst)

TODO
(reducesum f lst)
(if the list is empty, 0 is returned) 
TODO
(reduceproduct f lst)
(if the list is empty, 1 is returned) 
TODO
(reducemin f lst)
(if the list is empty,nil
is returned) 
TODO
(reducemax f lst)
(if the list is empty,nil
is returned) 
TODO
(append lst1 lst2)

TODO
(nth n lst)

TODO
(last n)

TODO
(delete e lst)

TODO
(deletenth n lst)

TODO
(maxby)

TODO
(minby)

TODO
(take n lst)

TODO
(zip lsts)

TODO
(windows n lst)

TODO
(chunks n lst)

TODO
(flatten lst)

TODO
(each f lst)

TODO
(eachwithindex f lst)
Parameters tof
: current element, index 
TODO
(concat lst)

TODO
(enumerate lst)
Turnslst
into a list of pairs(index . element)
Vectors

TODO
vectorinit!

TODO
vectorswap!

TODO
vectoradd!

TODO
vectorsub!
Operations on Ranges

TODO
rangeeach

TODO
reverserangeeach

TODO
rangecount

TODO
rangemax

TODO
rangemin

TODO
rangefirst

TODO
sum

TODO
product
Definitions & Assignment
Variable Assignment
(def name var)
Constant Assignment
(defconst name constant)
The difference between variables and constants is that the latter can't change during runtime and are constantfolded if possible.
TODO Example for constant folding
TODO Benchmark comparing variables & constants
Function Definitions
(defn name args body...)
defn
is implemented as a macro that expand to
(def name (fn args body...))
let
and
let*
(let ((var1 val1) (var2 val2) ...) body...)
let
evaluates
body
in an environment where
varN
is bound to
valN
.
All
valN
are evaluated in the same environment as the parent
let
.
(let* ((var1 val1) (var2 val2) ...) body...)
is equivalent to writing
(let ((var1 val1)) (let ((var2 val2)) body...))
Each
valN
is evaluated in an environment where the previous
varN
are already bound.
Flow Control, Conditionals
If, Unless, When
(if condition consequence) (if condition consequence alternative)
(unless condition consequence) (unless condition consequence alternative)
is equivalent to
(if (not condition) consequence alternative)
(when condition consequence...)
is equivalent to
(if condition (begin consequence...))
If no
alternative
is provided,
nil
is returned if the
condition
is false.
Cond
The branches of a conditional can have multiple forms. Below each form is used once for demonstrative purposes. Of course multiple branches can have the same form.
(cond (test1 result1...) (test2 => result2) (test3) (else result4))
If
test1
is true, the expressions
result1...
are evaluated and
the value of the last one is returned.
If
test2
is true,
(result2 test2)
is returned.
If
test3
is true, the value it evaluates to is returned.
Otherwise
result4
is returned.
If no
else
branch is defined and all tests evaluate to false,
nil
is returned.
Case
(case key (key1 result1) (key2 result2) (else result3))
If key is not an atom, it is evaluated first. Then it is compared to
the keys of each branch using
equal?
and the result of the first
matching branch is returned.
Threading Macro
The threading macro “folds” its argument by inserting the them as the last argument of the following expression.
(~> 1 (+ 5) square println)
Is the same as writing
(println (square (+ 5 1)))
Functions
Function Composition
comp
implements function composition.
(comp h g f)
returns a function
(fn (x) (h (g (f x))))
.