Variables
Variables in Nujel work like in most dynamically-typed languages, nothing too suprising here.
1. Defining variables
You can define new variables using def
and give old variables a new value using set!
.
my-temp ; You can access a variables value by evaluating the symbol :unbound-variable (def my-temp 123) ; Of course it needs to be defined first 123 my-temp 123
2. Setting variables
If you wish to change the value already associated with a given symbol, you can use set!
to achieve that.
(def my-temp 123) ; Gotta define it first before we can use set! (set! my-temp 234) my-temp 234
3. Let blocks
You can use let
to create a new context for assignments, you still have access to all symbols defined in parent contexts.
Warning
Currently you can shadow already defined variables, this is highly discouraged and will probably become an error in later Nujel versions. This is because it has already led to some bugs and makes some optimizations more complicated.
Unlike most other Lisps using let
is discouraged in most situations, since you can just use def
within a function call in order to define temporary variables, it is available though and should work like in Scheme or CL.
(let ((new-temp 123)) (println new-temp)) ; => 123 new-temp :unbound-variable