Why is #' (sharp-quote) notation unnecessary in CLISP?

后端 未结 3 806
执念已碎
执念已碎 2021-01-18 06:47

I\'m learning Lisp from the book \'Practical Common Lisp\'. At one point, I\'m supposed to enter the following bit of code:

[1] (remove-if-not #\'evenp \'(1          


        
3条回答
  •  我在风中等你
    2021-01-18 07:20

    Sharp-quote and quote do not have the same behaviour in the general case:

    (defun test () 'red)
    
    (flet ((test () 'green))
      (list (funcall 'test)
            (funcall #'test))) => (red green)
    

    Calling a quoted symbol will use the function value of the quoted symbol (ie, the result of symbol-function). Calling a sharp-quoted symbol will use the value established by the lexical binding, if any, of the symbol. In the admittedly common case that there is no lexical binding the behaviour will be the same. That's what you are seeing.

    You should get into the habit of using sharp-quote. Ignoring function bindings is probably not what you want, and may be confusing to anybody trying to understand your code.

提交回复
热议问题