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
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
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
which turns all symbols into identifiers.
(The same issue is described by mjt here,
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)
syntax-rules it's not difficult to distinguish
proper list and inproper list (see Gauche:lib/gauche/defvalues.scm).