Skip to content

The Lisp Evaluation Model

This is from Bagger's excellent Bits of Lisp youtube video

Self Evaluating Objects

numbers, (e.g. 1, -1, 1.616)
strings, (e.g. "Hello World")
keywords, (e.g. foo)

Lists

(+ 3 5)

The first item in a list is evaluated as a function. The rest of the items in the list are evaluated and then passed to the function,

However...

`(+ 3 5)

The back tick tells list not to evaluate the list and to treat it as data instead.

#'

This tells lisp to go and find the function named by this symbol.

Special Forms

The normal rules of evaluation don't apply to special forms. For example, the if function

(if (> 10 5)
    (wake-up)
    (go-to-sleep))

If this was processed as a list, both wake-up and go-to-sleep would be evaluated, but this isn't what we want - we only want one of the items to be run (in the above case wake-up). This is a the reason the progn is needed in the if statement, for example..

(if (> 10 5)
    (progn
       (wake-up)
       (get-up))
     (go-to-sleep))

Handy bits of Lisp

(type-of *) in the repl this will return the type of the last value returned in the repl.
(second lst) returns the second item in the list - kind of like cadr