[Larceny-users] define-macro library

Andre van Tonder andre at het.brown.edu
Fri Feb 13 20:05:06 EST 2009


Try changing the underscores to some identifier (for example k) in the 
definition of define-macro.  Underscores are not pattern variables any longer 
in r6rs, so the datum->syntax instance will not do the correct thing any longer. 
Haven't tested it but hopefully it will help.

On Fri, 13 Feb 2009, Eduardo Cavazos wrote:

> Hello,
>
> So, I've seen a few "define-macro using syntax-case" implementations
> floating around. This one loads and works for simple cases. But it has
> trouble when you reference non-rnrs-base functions in the body.
>
> For example, this works:
>
> ----------------------------------------------------------------------
> > (define-macro (test-macro a) `(list ,a))
>
> > (test-macro 10)
> (10)
> ----------------------------------------------------------------------
>
> but this doesn't:
>
> ----------------------------------------------------------------------
> > (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)
> ----------------------------------------------------------------------
>
> Any suggestions?
>
> Ed
>
> ----------------------------------------------------------------------
> (library
>
>  (define-macro)
>
>  (export define-macro)
>
>  (import
>
>   (for (rnrs base) run expand)
>
>   (for (rnrs syntax-case) run expand)
>
>   )
>
> (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)))))))))))))
>
>  )
>
> ----------------------------------------------------------------------
>
> _______________________________________________
> Larceny-users mailing list
> Larceny-users at lists.ccs.neu.edu
> https://lists.ccs.neu.edu/bin/listinfo/larceny-users
>
>



More information about the Larceny-users mailing list