This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Spec of syntax-case
- From: "jocelyn paine" <ireson_paine at hotmail dot com>
- To: kawa at sources dot redhat dot com
- Date: Sun, 12 May 2002 08:53:58 +0000
- Subject: Spec of syntax-case
- Bcc:
I think I'm finding that syntax-case doesn't act as I'd expect it to from
the Dybvig specification. I tried loading a source file which
contains
(define-syntax test-or
(lambda (x)
(syntax-case x ()
((_)
(syntax #f)
)
((_ e)
(syntax e)
)
((_ e1 e2 e3 ...)
(syntax (let ((t e1))
(if t t (test-or e2 e3 ...))
)
)
)
)
)
)
which is Dybvig's example of how to implement 'or', and got
#|kawa:1|# (load "test.scm")
test.scm:12:28: evaluating syntax transformer `test-or' threw
java.lang.NullPointerException:
I also tried
(define-syntax test
(lambda (x)
(syntax-case x ()
((_ e)
(identifier e)
(syntax 'id)
)
)
(syntax-case x ()
((_ e)
(integer? e)
(syntax 'int)
)
)
)
)
This loads OK, but when I try expanding it applied to an identifier, doesn't
recognise the 'identifier?' function called in the "fender":
#|kawa:1|# (load "t.scm")
#|kawa:2|# (test a)
<msg_stdin>:2:2: evaluating syntax transformer `test' threw
gnu.mapping.UnboundSymbol: Unbound symbol identifier?
Removing the branch with identifier? in it (lines 3 to 8 in the definition)
and expanding the macro applied to an integer gives:
#|kawa:1|# (load "t.scm")
#|kawa:2|# (test 1)
<msg_stdin>:2:2: evaluating syntax transformer `test' threw
gnu.mapping.UnboundSymbol: Unbound symbol syntax
So the call to integer? in its "fender" has succeeded, but then the macro
isn't generating the result it should.
What I want to do is use macros to implement a pattern-matcher. Some of my
patterns will be lists that may contain identifiers to be bound, or
constants to be matched literally, e.g.
(pattern 1 x 1 y 'a)
should match any 5-element list with 1 in 1st and 3rd positions and 'a in
the 5th. syntax-rules is insufficient for this, because my macro has to
recognise whether each element is a constant, variable, etc., and generate
code appropriately. (Hence the experimenting with the type tests in the
definition above.) Can I do this with Kawa's current implementation of
syntax-case, and where should I look to find out what's implemented?
Jocelyn Paine
http://www.ifs.org.uk/~popx/
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com