Global and local bindings

Definition (def)

(def name meta? value)

This special form binds a value to a global symbol. A definition cannot be redefined at a later point.

(def my-name "phel")
(def sum-of-three (+ 1 2 3))

To each definition metadata can be attached. Metadata is either a Keyword, a String or a Table.

(def my-private-variable :private 12)
(def my-name "Stores the name of this language" "Phel")
(def my-other-name @{:private true :doc "This is my doc"} "My value")

Local bindings (let)

(let [bindings*] expr*)

Creates a new lexical context with variables defined in bindings. Afterwards the list of expressions is evaluated and the value of the last expression is returned. If no expression is given nil is returned.

(let [x 1
      y 2]
  (+ x y)) # Evaluates to 3

(let [x 1
      y (+ x 2)]) # Evaluates to nil

All variables defined in bindings are immutable and cannot be changed.