This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: define-syntax and context


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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]