Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Lisp (Clojure, Emacs Lisp), what is the difference between list and quote?

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?

like image 780
neo Avatar asked Oct 09 '10 08:10

neo


People also ask

What does quote mean in Lisp?

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) .

Is Emacs Lisp the same as Lisp?

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.

What is Emacs Lisp used for?

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.

Is clojure similar to Lisp?

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.


1 Answers

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] 
like image 191
Alex Taggart Avatar answered Sep 16 '22 14:09

Alex Taggart