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

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

    In Common Lisp, '1 is shorthand for (QUOTE 1). When evaluated, (QUOTE something) returns the something part, unevaluated. However, there is no difference between 1 evaluated and 1 unevaluated.

    So there is a difference to the reader: '1 reads as (QUOTE 1) and 1 reads as 1. But there is no difference when evaluted.

提交回复
热议问题