Is there any way to have both the syntax-case macros and use Gambit's DSSSL parameters at the same time? I found that you can't use them normally after loading the file, as in
(load "~~/syntax-case.scm")
"/usr/local/Gambit-C/4.0b22/syntax-case.scm"> (load "~~/syntax-case.scm")
(define (foo x #!key y)
(list x y)) *** ERROR -- invalid syntax (define (foo x #!key y) (list x y))> (define (foo x #!key y) (list x y))
However, if I do
(##define (foo x #!key y)
(list x y))
It works fine. Okay.
But now, if I were to try this:
(define-syntax twice
(syntax-rules () ((_ x) (begin x x))))
(##define (bar x)
(twice x))
(bar 5)
** ERROR IN bar, (stdin)@55.2 -- unbound variable twice
So, once I've loaded syntax-rules, I can only use the DSSSL extensions in ##define forms, but I can only use syntax macros in define forms. Is there any way around this? Do I have to prefix the syntax macros with a specific namespace? I'm assuming that's what the problem is, the macros being in a different namespace...but which one?
Kind of curious, James
Afficher les réponses par date
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 21-May-07, at 8:24 PM, James Cash wrote:
So, once I've loaded syntax-rules, I can only use the DSSSL extensions in ##define forms, but I can only use syntax macros in define forms. Is there any way around this? Do I have to prefix the syntax macros with a specific namespace? I'm assuming that's what the problem is, the macros being in a different namespace...but which one?
No that's not the problem. The syntax-case system has its own macro expander that operates before the Gambit built-in expander. The syntax-case system is the portable syntax-case implementation (version 7.3) extended to treat the forms "##define", "##define- macro", etc like "core" forms (for which the arguments are not macro- expanded). So if you type the expression E it is macro-expanded to E' by the syntax-case macro expander, and then the Gambit parser expands the macros built-in to Gambit to get E'' which is then assigned a meaning according to the forms known to Gambit, including things like "##define" and the DSSSL parameter notation.
So, if E is
(##define (bar x) (twice x))
the syntax-case expander classifies this as a core form with *no* macro-expansion of the arguments. So the macro-expansion produces E' which is identical to E. Then the Gambit interpreter (or compiler) will classify this as a definition of function bar with a body that is a *function* call to twice (instead of the intended syntax-case *macro* call to twice).
There is no easy general fix. But you can play around with the file misc/psyntax73.ss to modify the handling of ##define so that the syntax-case expander expands the body before handing it to Gambit. Sorry I can't suggest the correct code (I have a limited understanding of how that code works). After modifying psyntax73.ss you can build a new syntax-case.scm by running the shell script syntax-case-build .
Marc