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

前端 未结 3 1163
说谎
说谎 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:12

    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]
    

提交回复
热议问题