Search code examples
common-lispon-lisp

"On Lisp": `(a b c) vs '(a b c) vs (list 'a 'b 'c)


In On Lisp (p. 84) Graham says

‘(a b c) (without comma) is equal to ’(a b c)

and then says

A backquoted list is equivalent to a call to list with the elements quoted.
That is, ‘(a b c) (without comma) is equal to (list ’a ’b ’c).

One statement has to be false since '(a b c) and (list 'a 'b 'c) don't seem to be equal. The latter is a freshly consed list (safe to modify) while the former is a constant -- or at least the spec allows the compiler to treat it as such.

So maybe it's a very nitpicky question but is a backquoted list (without comma) like ‘(a b c) equal to '(a b c) or equal to (list 'a 'b 'c)?


Solution

  • Equal and Equivalent are not the same.

    Certainly (equal '(a b c) (list 'a 'b 'c)) returns t, but, as you correctly note yourself, '(a b c) is a quoted constant while (list 'a 'b 'c) is freshly allocated.