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

前端 未结 3 1164
说谎
说谎 2020-12-29 20:32

From reading introductory material on Lisp, I now consider the following to be identical:

(list 1 2 3)

\'(1 2 3)

However, judging from pro

3条回答
  •  醉话见心
    2020-12-29 21:32

    Quoted lists (e.g. '(1 2 3)) should be treated carefully (generally as read-only). (see SO answers When to use 'quote in Lisp and When to use 'quote in Lisp).

    (list 1 2 3) will "cons" up a fresh list, independent of all others.

    You can see an example of a pitfall of using quoted lists in the manual for nconc.

    And, as you probably know, when you call 'list - the arguments will obviously be evaluated versus the contents of a quoted list. And 'quote takes a single argument, versus 'lists variable number of arguments.

    (list (+ 1 2) 3)     -->  (3 3)
    (quote ((+ 1 2) 3))  -->  ((+ 1 2) 3)
    

提交回复
热议问题