What is the difference between 1 and '1 in Lisp?

后端 未结 7 470
迷失自我
迷失自我 2021-02-01 02:34

I had never really thought about whether a symbol could be a number in Lisp, so I played around with it today:

> \'1
1
> (+ \'1 \'1)
2
> (+ \'1 1)
2
>         


        
7条回答
  •  孤街浪徒
    2021-02-01 03:11

    Quoting prevents expressions from being evaluated until later. For example, the following is not a proper list:

    (1 2 3)
    

    This is because Lisp interprets 1 as a function, which it is not. So the list must be quoted:

    '(1 2 3)
    

    When you quote a very simple expression such as a number, Lisp effectively does not alter its behavior.

    See Wikipedia: Lisp.

提交回复
热议问题