This is the mail archive of the kawa@sourceware.org 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: Strange error output for undefined macros inside macros


Kjetil S. Matheussen wrote:


On Thu, 1 Feb 2007, Per Bothner wrote:
 (define (low-level-macro-helper all)
   (eval `(dosomethingcoolwith ,@all)))

 (define-syntax low-level-macro
   (syntax-rules ()
     ((_ arg1 arg2 ...) (def-class-helper (quote (arg1 arg2 ...))))))

I don't know if it is safe, but I'm 99% certain it's the wrong approach. You want to work *with* the compiler, not *against* it.

But will I stumble upon the colon problem using this approach?

The "colon problem" is just an example. You'll only run into it if you use identifiers containing colons, and in that case you can escape the colon.

If you really don't want to do the right thing (i.e. define-syntax),
t least dont't use eval to fake low-level macros.  That's even worse
than using defmacro or define-macro: it combines the problems
of defmacro with breaking efficiency, static error detection, and
lexical scoping.

But I really suggest trying to use the define-syntax-case macro
from http://sourceware.org/ml/kawa/2006-q4/msg00020.html .
That gives you a fairly direct way of mapping defmacro macros
to syntax-case macros:

Typically, you can translate:
  (defmacro (NAME PATTERN-VAR ...) `(... PATTERN_VAR ...))
to:
(define-syntax-case NAME ()
  ((_ PATTERN_VAR ...) #`(... PATTERN_VAR ...))
and:
 (defmacro (NAME ...)
   (let ... `(... ,EXP ...)))
to:
  (define-syntax-case NAME ()
     ((_ ...) (let #`(... ,EXP ...))))

At the very least, if you use defmacro you have a chance of fixing
them to use syntax-case.  If you use eval that is probably harder.
--
	--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]