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

后端 未结 3 779
执念已碎
执念已碎 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:41

    This is not CLISP specific, it works in every Common Lisp implementation (I use Clozure Common Lisp here).

    What happens is that if you give a symbol as a function designator then the implementation will look up the symbol-function (assuming the symbol is available in the global environment) for you:

    ? #'evenp
    #
    ? (symbol-function 'evenp)
    #
    

    In general you can use either, but there's an interesting effect if you rebind the called function later. If you specify the function (#' or (function)) then the calls will still call the old function because the lookup has been done at compile time; if you use the symbol then you will call the new function because the lookup is re-done at runtime. Note that this may be implementation-specific.

提交回复
热议问题