Defining the defmacro
function using only LISP primitives?
.
McCarthy’s Elementary S-functions and predicates were
atom
,eq
,car
,cdr
,cons
.
He then went on to add to his basic notation, to enable writing what he called S-functions:
quote
,cond
,lambda
,label
.
On that basis, we’ll call these “the LISP primitives”…
How would you define the defmacro
function using only these primitives in the LISP of your choice?
edited Aug 21 ’10 at 2:47
Isaac
asked Aug 21 ’10 at 2:02
hawkeye
.
Every macro in Lisp is just a symbol bound to a lambda with a little flag set somewhere, somehow, that eval
checks and that, if set, causes eval
to call the lambda at macro expansion time and substitute the form with its return value. If you look at the defmacro
macro itself, you can see that all it’s doing is rearranging things so you get a def
of a var
to have a fn
as its value, and then a call to .setMacro
on that var
, just like core.clj
is doing on defmacro
itself, manually, since it doesn’t have defmacro
to use to define defmacro
yet.
– dreish Aug 22 ’10 at 1:40
.
.
2018.11.17 Saturday (c) All rights reserved by ACHK