2013/09/18
Macro system extension
I finally added syntax-rules
extensions (srfi:46) to Gauche,
that makes Gauche's hygienic macro system compatible to R7RS
(except a few known bugs).
The current hygienic macro expander is written in C which is
an ugly pile of spaghetti. Originally I planned to ditch
the legacy code and to write an explicit-renaming macro expander
as the new basis of our hygineic macro system, then
to implement syntax-rules
on top of it.
I like ER-macro since it's transparent to what it is doing for
hygienity. It doesn't necessary to be the easiest one to use---
destructuring the input form, then renaming identifiers explicitly
would be cumbersome for day-to-day programming.
But those things can be easily alleviated
by combining other tools. For example, we can just use util.match
matcher to destructure the input form (instead of yet another pattern
matcher tied to macro system).
In fact, in er-macro
branch in the repo I implemented ER-macro
expander to some extent. But it turned out I need some more time
to substitute the low-level macro layer completely.
A major issue is to keep compatibility between ER-macro, which
allows raw symbols inserted by the macro expander to capture
symbols in macro calls, and the current syntax-rules
implementation
which turns all symbols into identifiers.
(The same issue is described by mjt here,
in Japanese.)
Since I'd like to push out R7RS compatible release sooner, I just went into the legacy code and added some more spaghetti to make it work as srfi:46.
* * *
I realized this enhancement makes syntax-rules
a lot more
useful. I also adapted define-values
form to R7RS, which
allows generic formals, as follows:
(define-values (x y . z) (values 1 2 3 4)) z => (3 4)
With R7RS syntax-rules
it's not difficult to distinguish
proper list and inproper list (see Gauche:lib/gauche/defvalues.scm).
Peter Bex (2013/09/18 21:40:37):
shiro (2013/09/19 03:30:46):
Peter Bex (2013/09/19 17:50:07):
shiro (2013/09/20 15:25:22):
Peter Bex (2013/09/20 16:39:57):
Sam Tobin-Hochstadt (2013/12/12 03:58:14):
shiro (2013/12/12 04:40:39):