Search code examples
schemelisp

Is quote in Lisp/Scheme same as a string?


There are already many questions regarding quote in Lisp, and I understand that it doesn't evaluate the expression. But I haven't seen its comparison to a string.

Is the quote same as a string? If not, how are they different?


Solution

  • In Lisp:

    * (type-of "a b c")
    (SIMPLE-ARRAY CHARACTER (5))
    * (type-of '(a b c))
    CONS
    * (type-of "(a b c)")
    (SIMPLE-ARRAY CHARACTER (7))
    

    A string is always an object of some string type. A string always evaluates to itself.

    The quote operator returns the quoted object - whatever that object may be: a string, a number, a symbol, a list made of cons cells, ...

    CL-USER 2 > '"a b c"
    "a b c"
    
    CL-USER 3 > '3
    3
    
    CL-USER 4 > 'abc
    ABC
    
    CL-USER 5 > '(a b c)
    (A B C)