5 ms·
> macros statically evaluate their inputs ie. at compile-time Unless one uses an interpreter. CL-USER 1 > (defmacro my-if (test a b) (print
by lispm 4y ago
> macros statically evaluate their inputs ie. at compile-time
Unless one uses an interpreter.
CL-USER 1 > (defmacro my-if (test a b)
(print "Hi, I'm the executing MY-IF macro")
`(if ,test ,a , b))
MY-IF
CL-USER 2 > (defun foo (a)
(my-if (> a 10) 'big 'small))
FOO
CL-USER 3 > (foo 11)
"Hi, I'm the executing MY-IF macro"
"Hi, I'm the executing MY-IF macro"
BIG
CL-USER 4 > (foo 2)
"Hi, I'm the executing MY-IF macro"
"Hi, I'm the executing MY-IF macro"
SMALL
In this Lisp implementation, the macro even runs twice on each runtime invocations.
- tempodox 4y agoSBCL to the rescue. It compiles everything you enter in the REPL.
- lispm 4y agoUnless one uses an interpreter: $ /usr/local/bin/sbcl This is SBCL 2.2.1, an implementation of ANSI Common Lisp. More information about SBCL is available at <http://www.sbcl.org/>. SBCL is free software, provided as is, with absolutely no warranty. It is mostly in the public domain; some portions are provided under BSD-style licenses. See the CREDITS and COPYING files in the distribution for more information. * *evaluator-mode* :COMPILE * (setf *evaluator-mode* :interpret) :INTERPRET * (defmacro my-if (test a b) (print "Hi, I'm the executing MY-IF macro") `(if ,test ,a , b)) MY-IF * (defun foo (a) (my-if (> a 10) 'big 'small)) FOO * (foo 11) (foo 11) "Hi, I'm the executing MY-IF macro" BIG