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

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

    As has been pointed out, there is no difference, as numbers evaluate to themselves. You can confirm this by using eval:

    (eval 1)  ;=> 1
    

    This is not limited to numbers, by the way. In fact, in Common Lisp, most things evaluate to themselves. It's just that it's very rare for something other than numbers, strings, symbols, and lists to be evaluated. For instance, the following works:

    (eval (make-hash-table))  ;equivalent to just (make-hash-table)
    
    0 讨论(0)
提交回复
热议问题