Quoting in Lisp
A quote is the difference between running (+ 2 3) and holding on to it.
;; quote holds a form back instead of running it
(defparameter *sum* (+ 2 3))
(defparameter *unrun* '(+ 2 3))
(format t "evaluated ~a, quoted ~a~%" *sum* *unrun*)
;; symbols are ordinary data once quoted, not just names of variables
(defparameter *weekdays* '(monday tuesday wednesday))
(format t "second day: ~a~%" (second *weekdays*))
(format t "spelled out: ~a~%" (symbol-name 'friday))
;; eq asks whether two things are the same object, equal compares shape
(format t "eq on symbols: ~a~%" (eq 'monday 'monday))
(format t "eq on fresh lists: ~a~%" (eq (list 1 2) (list 1 2)))
(format t "equal on fresh lists: ~a~%" (equal (list 1 2) (list 1 2)))
How it works
(+ 2 3)evaluates to 5 while'(+ 2 3)stays a three-element list.'(monday tuesday wednesday)treats symbols as data, reachable withsecondand readable withsymbol-name.eqis true for two references to'mondaybut false for two fresh lists thatequalaccepts.
Keywords and builtins used here
defparametereqequalformatlistsecond
The run, in numbers
- Lines
- 14
- Characters to type
- 651
- Tokens
- 103
- Three-star pace
- 70 tpm
At the three-star pace of 70 tokens a minute, this run takes about 88 seconds.
Step 3 of 3 in Lists & conses, step 6 of 27 in Language basics.