From reading introductory material on Lisp, I now consider the following to be identical:
(list 1 2 3) '(1 2 3)
However, judging from problems I face when using the quoted form in both Clojure and Emacs Lisp, they are not the same. Can you tell me what the difference is?
Because quote is used so often in programs, Lisp provides a convenient read syntax for it. An apostrophe character (' ' ') followed by a Lisp object (in read syntax) expands to a list whose first element is quote , and whose second element is the object. Thus, the read syntax 'x is an abbreviation for (quote x) .
By default, Common Lisp is lexically scoped, that is, every variable is lexically scoped except for special variables. By default, Emacs Lisp files are dynamically scoped, that is, every variable is dynamically scoped.
Emacs Lisp is a dialect of the Lisp programming language used as a scripting language by Emacs (a text editor family most commonly associated with GNU Emacs and XEmacs). It is used for implementing most of the editing functionality built into Emacs, the remainder being written in C, as is the Lisp interpreter.
Clojure is a member of the Lisp family of languages. Many of the features of Lisp have made it into other languages, but Lisp's approach to code-as-data and its macro system still set it apart. Clojure extends the code-as-data system beyond parenthesized lists (s-expressions) to vectors and maps.
The primary difference is that quote
prevents evaluation of the elements, whereas list
does not:
user=> '(1 2 (+ 1 2)) (1 2 (+ 1 2)) user=> (list 1 2 (+ 1 2)) (1 2 3)
For this reason (among others), it is idiomatic clojure to use a vector when describing a literal collection:
user=> [1 2 (+ 1 2)] [1 2 3]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With