From Newsgroup: comp.lang.lisp
Mario Rosell <
mario@mariorosell.es> wrote:
[ Repost from Reddit. r/lisp: https://t.ly/Fldzk ]
Hello everyone.
I am making a Scheme R5RS implementation and it is going pretty well.
I am trying implement macros, and don't really know how to implement them. Scheme has a pretty complex macro system, so for now I am trying to
implement defmacro and then implement define-syntax, syntax-case, etc.
Any tips?
Naive macros are easy: when you see macro definition you handle
it almost as a function, except for that you mark resulting
object as a macro. In evaluator (or in compiler if you have one)
you first check if the form is a macro call (that is head is marked as
a macro), if it is than you execute corresponding macro function applying
it to unevaluated arguments. When macro function returns you
handle result as new source code.
Once you have naive macros you can add niceties like quasiquote
by preprocessing the macro definition. In other words, better
macro can be implemented as macro definition which processes
its argument and then passes it to naive macro.
I am not familiar with details of Scheme macros, but it is quite
likely that they could be implemented in similar way on top of
naive macros.
--
Waldek Hebisch
--- Synchronet 3.22a-Linux NewsLink 1.2