Use of # a.k.a. read-macro

前端 未结 4 983
天涯浪人
天涯浪人 2021-01-22 03:26

Reading book \"Let Over Lambda\" by Doug Hoyte, I found the following description of #. sign, a.k.a. read-macro:

A basic read macro that come

4条回答
  •  心在旅途
    2021-01-22 04:18

    Another difference between using #'foo and 'foo as function designators is that #'foo evaluates to a function object, but 'foo evaluates to a symbol. So using 'foo transfers the work of finding the function object to a later time. That can be a noticeable performance hit if you do it in every cycle of a loop instead of just once.

    CL-USER> (defun foo () 42)
    FOO
    CL-USER> (read-from-string "'foo")
    => (QUOTE FOO), 4
    
    CL-USER> (eval *)
    FOO
    CL-USER> (read-from-string "#'foo")
    => (FUNCTION FOO), 5
    
    CL-USER> (eval *)
    => #
    

提交回复
热议问题