[Larceny-users] define-macro library
Eduardo Cavazos
wayo.cavazos at gmail.com
Fri Feb 13 20:40:09 EST 2009
Eduardo Cavazos wrote:
> ----------------------------------------------------------------------
> > (define (sq n) (* n n))
>
> > (define-macro (test-macro-sq a) `(list (sq ,a)))
>
> > (test-macro-sq 10)
>
> Syntax violation: invalid reference
>
> No binding available for sq in library (define-macro)
> ----------------------------------------------------------------------
So... the way I got around this problem is to *not* put 'define-macro'
in it's own Larceny library (i.e. *.sls) file.
What I'm doing right now is evaluating this at the toplevel in ERR5RS mode.
----------------------------------------------------------------------
(import
(for (rnrs base) run expand)
(for (rnrs syntax-case) run expand)
(for (rnrs bytevectors) run expand)
(for (rnrs control) run expand)
(rnrs io simple)
(err5rs records syntactic)
(err5rs load)
(primitives current-directory file-exists?)
)
(define-syntax define-macro
(lambda (x)
(syntax-case x ()
((_ (name . args) . body)
(syntax (define-macro name (lambda args . body))))
((_ name transformer)
(syntax
(define-syntax name
(lambda (y)
(syntax-case y ()
((_ . args)
(datum->syntax
(syntax _)
(apply transformer
(syntax->datum (syntax args)))))))))))))
----------------------------------------------------------------------
Of course, I don't copy and paste that into the listener each time... I
have that in a file called 'src/boot/larceny/larceny.scm' and I start
larceny like this:
cat src/boot/larceny/larceny.scm - | larceny -err5rs
Kludges FTW! :-)
Anywho, the above works for my purposes for now. I hope that eventually
there'll be an implementation of 'define-macro' available in the Larceny
distribution which is blessed by the core team.
Ed
More information about the Larceny-users
mailing list