This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: define-syntax and context
- From: Per Bothner <per at bothner dot com>
- To: Christof Lehmann <clehmann at vub dot de>
- Cc: Kawa Mailingliste <kawa at sources dot redhat dot com>
- Date: Tue, 09 Mar 2004 16:41:42 -0800
- Subject: Re: define-syntax and context
- References: <1078824856.8112.47.camel@localhost>
Christof Lehmann wrote:
(define-syntax myfunc
(syntax-rules ()
((myfunc body-expr)
(lambda (left right) body-expr))))
(display ((myfunc (+ right left)) 3 5))
I get allways the following exception:
gnu.mapping.UnboundSymbol: Unbound symbol right
I have two question:
- Is my construct correct in scheme?
No. The scope of the identifiers 'left and 'right is
local to the macro expansion, and so not within the
scope of the 'left and 'right in the display. This is
what "macro hygiene" means: strict lexical scoping,
even for macro expansions.
- if not, how should I express this?
You can't do it with syntax-rules, but you can probably
do it with defmacro - see the Kawa manual. (It does need
an example, I'm afraid, but there are a couple in the
testsuite - look for arithmetic-if.)
Also look at the cut and cute macros from SRFI-26; the
implementation is in gnu/kawa/slib/cut.scm.
--
--Per Bothner
per@bothner.com http://per.bothner.com/