[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: syntax-case problems
From: |
Keith Wright |
Subject: |
Re: syntax-case problems |
Date: |
Sat, 14 Sep 2002 11:13:23 -0400 |
> From: Ingo Ruhnke <address@hidden>
>
> I am trying to define a simple macro which should transform a:
>
> (mydefine a 5) into: (define a-var 5)
>
> The following code should be correct for that and it works in
> mzscheme, but doesn't work in Guile 1.6.0:
>
> (use-modules (ice-9 syncase))
> (define-syntax mydefine
> (lambda (expr)
> (syntax-case
> expr ()
> ((_ var value)
> (with-syntax ((newvar (string->symbol
> (string-append
> (symbol->string (syntax-object->datum
> (syntax var)))
> "-var"))))
> (syntax (define newvar value))))
> )))
>
> guile> (mydefine a 5)
> ERROR: encountered raw symbol in macro output a-var
> ABORT: (misc-error)
Are you sure that works in mzscheme? It looks like it has
a raw symbol in the macro output. With SYNTAX-CASE, symbols
are no longer the same as identifers, because identifiers
are syntax objects and so have scope information attached.
Dybvig's paper "Syntactic Absraction in Scheme" uses the
procedure IMPLICIT-IDENTIFER to do the conversion, but that
is not included in the implementation that was pasted into Guile.
Instead the procedure DATUM->SYNTAX-OBJECT seems to do about
the same thing. I am not sure which of these is "correct" or
whence the difference, but the following works:
(define-syntax mydefine
(lambda (expr)
(syntax-case expr ()
((_ var value)
(with-syntax
((newvar (datum->syntax-object
(syntax _) ; identifier to give scope
(string->symbol
(string-append
(symbol->string (syntax-object->datum (syntax var)))
"-var")))))
(syntax (define newvar value)) )))))
guile> (mydefine a 5)
guile> a-var
5
--
-- Keith Wright <address@hidden>
Programmer in Chief, Free Computer Shop <http://www.free-comp-shop.com>
--- Food, Shelter, Source code. ---