Calling function from macro inside Quicklisp package

后端 未结 1 729
孤城傲影
孤城傲影 2021-01-13 03:03

I put failing.asd

(in-package :asdf-user)                    

(defsystem \"failing\"                       
  :description \"some code dest         


        
相关标签:
1条回答
  • 2021-01-13 03:36

    That can only happen when the file gets compiled before loaded. Generally it has nothing to do with ASDF (which is a tool to manage file dependencies and to compile/load code) or packages (which are namespaces and are not in any way related to ASDF).

    It has to do with how file compilation works in Common Lisp:

    The file compiler sees the function foo and compiles it -> the code for it gets written to a file. It does not (!) load the code into the compile-time environment.

    The file compiler then sees the macro bar and compiles it -> the code gets written to a file. It does (!) load the code into the compile-time environment.

    The file compiler then sees the macro form (bar) and wants to expand it. It calls the macro function bar. Which calls foo, which is undefined, since it is not in the compile-time environment.

    Solutions:

    • put the function definition in a separate file in the ASDF system and compile/load it earlier.

    • put the function inside the macro as a local function

    • put (EVAL-WHEN (:COMPILE-TOPLEVEL :LOAD-TOPLEVEL :EXECUTE) ...) around the function definition. It causes the definition to be executed at compile-time.

    Remember: the file compiler needs to know macro functions -> otherwise it would not be able to macroexpand code. Ordinary functions just get compiled, but not loaded at compile time, during compilation of a file.

    0 讨论(0)
提交回复
热议问题