1. List Functions

Form Description Examples

(first lst)

Return the first element contained in lst. If lst is empty, return nil.

(first '(1 2 3 4))
=> 1

(first ())
=> nil

(rest lst)

Return a new list with all the elements of lst except the first one. If lst is empty, return the empty list.

(rest '(1 2 3 4))
=> (2 3 4)

(rest ())
=> ()

(cons x lst)

Return a new list where x is the first element and lst is the rest.

(cons 4 '(1 2 3))
=> (4 1 2 3)

(empty? lst)

Return true if lst is an empty list, or false if it’s not an empty list.

(empty? ())
=> true

(empty? '(1 2 3))
=> false

(count lst)

Return the number of elements in lst. A nested list counts as one element.

(count '(3 1 8 5))
=> 4

(count '((3 1) ((8)) () 5))
4

2. Special Forms

Form Description Examples

(def name value)

Binding definition: Define a new global binding called name, bound to value.

(def x (* 6 7))

(defn name
docstring
[param1 param2 …​]
body)

Function definition: Define a new global function called name with a docstring, the specified (possibly zero) parameters, and the given body.

(defn add1
  "Returns x plus one."
  [x]
  (+ x 1))

(if test then else)

Condition: If test expression evaluates to a non-falsy value, evaluate and return the then expression. Otherwise, evaluate and return the else expression.

Falsy values are: false and nil.

(if (< 1 3) (* 2 3) (* 4 5))
=> 6

(if (> 1 3) (* 2 3) (* 4 5))
=> 20