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

后端 未结 7 635
迷失自我
迷失自我 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:23

    In Lisp, the apostrophe prevents symbols to be evaluated. Using an apostrophe before a number is not forbidden, it is not necessary as the numbers represent themselves. However, like any other list, it automatically gets transformed to an appropriate function call. The interpreter considers these numbers coincide with their value.

提交回复
热议问题