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

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

    In Lisp, quote prevent the following expression to be evaluated. ' is a shorthand for quote. As a result, '1 is same as (quote 1).

    However, in Lisp, symbols can never be a number. I mean, 'abc is a symbol, but '123 is not (evaluated into) a symbol. I think this is wrong of the design of Lisp. Another case is not only #t or #f can be used as a Boolean expression.

提交回复
热议问题