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

前端 未结 4 986
天涯浪人
天涯浪人 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:11

    You can call global definitions of functions both ways:

    CL-USER> (defun test nil t)
    TEST
    CL-USER> (funcall #'test)
    T
    CL-USER> (funcall 'test)
    T
    

    But see this:

    CL-USER 10 > (defun foo () 42)
    FOO
    
    CL-USER 11 > (flet ((foo () 82))
                   (print (foo))
                   (print (funcall 'foo))
                   (print (funcall #'foo)))
    
    82   ; the local definition
    42   ; the symbol references the global definition
    82   ; (function foo) / #'foo  references the local definition
    

    (funcall 'foo) looks up the function from the symbol.

    (funcall #'foo) calls the function from the lexical environment. If there is none the global definition is used.

    #'foo is a shorthand notation for (function foo).

    CL-USER 19 > '#'foo
    (FUNCTION FOO)
    

提交回复
热议问题