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

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

    As you have noticed (or read) funcall et. al. are will make an effort to convert the function argument you provide into something approprate. So as you have noticed they will take a symbol and then fetch the symbol-function of that symbol; if that works out they will then invoke that.

    Recall that #'X is converted at readtime into (symbol-function x) and 'x into (quote x). It's good practice to have the symbol-function work done at compile time.

    But why? Well two trival reasons it is slightly faster and it signals that you don't intend to redefine F's symbol-function after compile time. Another reason is that in a recent Pew Research study 98.3% of Lisp developers prefer it, and 62.3% will shun those that don't do this.

    But there's more.

    '(lambda (..) ...) is quite different v.s. #'(lambda (..) ...). The first is very likely to end up using eval, i.e. it will be slow. The first runs in a different scope v.s. the second one, i.e. only the second one can see the lexical scope it appears in.

提交回复
热议问题