Reading — step 1 of 5
Read
~1 min readEvaluator
Define & If
define binds a symbol to a value:
(define x 42)
(define name "Alice")
(define area (* 3.14 r r)) ; r must be defined
It's a SPECIAL FORM: the first argument (the symbol name) is NOT evaluated — that would try to look up x, which doesn't exist yet.
python
if is also special: only evaluate the chosen branch.
(if (< x 0)
(- x) ; evaluated only if x < 0
x) ; evaluated only if x >= 0
python
Lisp's "true" is anything except false and nil in Scheme; just false in Common Lisp; nil and false in Clojure. We'll use Python False and 0 as falsey to match Python conventions.
Special forms list grows: define, if, lambda, quote, set!, begin, let. Everything else is a function call.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…