Hi,
I've been reading through Nils M Holm's type inferencer lately, and among other things, I've found that it would benefit from using a pattern matcher instead of cadadars and predicates.
So I rewrote some bits of it to use the pattern matcher syntax specified in SRFI-200, but since it contained "disjunction patterns", which SRFI-200 does not support (e.g. it checked for "let*" forms in addition to "let" forms), I thought that it would
perhaps be beneficial to normalize the source code (i.e. expand all the macros) before performing inference on it.
With this in mind, I have digged out some work on "syntax impansion" that I've been doing along with writing my master thesis.
Therein, I have created a pattern language similar to syntax-rules. The key difference is that it uses the quote operator to match/produce literal symbols.
For example, some of the core Scheme macros can be expressed as
(define core-macros
'((('let ((name value) ...)
. body)
(('lambda (name ...) . body) value ...))
(('let* () . body)
('begin . body))
(('let* ((name-1 value-1)
(name-2 value-2) ...)
. body)
('let ((name-1 value-1))
('let* ((name-2 value-2) ...)
. body)))
(('and)
#true)
(('and last)
last)
(('and first second . rest)
('if first ('and second . rest) #false))
(('or)
#false)
(('or last)
last)
(('or first second . rest)
('let ((result first))
('if result result ('or second . rest))))))
Since the templates and the patterns are symmetrical, the expander can operate in both ways. There is a variant of the expander which also produces a "track" which contains the information, which rules were used for the transformation, and at which
positions.
The track can be used to revert the process of macro expansion, if the rules allow.
The source is available (as a Guile module) here:
https://github.com/plande/lambda-meta/blob/master/lambda/expand.scm
It should be fairly easy to read, but the essential bits of the implementation are described in an appendix to my thesis:
https://github.com/panicz/master-thesis/blob/master/chapters/C.tex
It requires the (grand scheme) glossary to run. The (grand scheme) is a set of forms and procedures which allow to write more succinct and readable Scheme code. In particular, it extends the core Scheme forms like lambda or let with the destructuring
capabilities (see SRFI-201 and SRFI-202 for more details)
The implementation of (grand scheme) for Guile can be obtained here:
https://github.com/plande/grand-scheme
An incomplete port to Racket can be found here:
https://github.com/panicz/sracket
(files "ground-scheme.rkt" and "grand-syntax.rkt")
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)