I have code that generates code (like say-hello), and the simplest way I found to make functions with that generated code is to put a defun in an eval like so:
(defun say-hello () `(princ "test")) (eval `(defun test () ,(say-hello))) (test) This file runs fine on the command line:
sbcl --script test.lisp But complains when I try to compile it inside SBCL:
* (compile-file "test.lisp") ; compiling file "test.lisp" (written 19 APR 2018 01:05:19 PM): ; compiling (DEFUN SAY-HELLO ...) ; compiling (EVAL (SB-INT:QUASIQUOTE #)) ; compiling (TEST) ; file: test.lisp ; in: TEST ; (TEST) ; ; caught STYLE-WARNING: ; undefined function: TEST ; ; compilation unit finished ; Undefined function: ; TEST ; caught 1 STYLE-WARNING condition ; test.fasl written ; compilation finished in 0:00:00.031 #P"test.fasl" T NIL * Is there a way I can write my code to avoid this compilation error? Is there a better idiom for creating code from functions that generate code?