Strange error output for undefined macros inside macros

Per Bothner per@bothner.com
Fri Feb 2 02:22:00 GMT 2007


Kjetil S. Matheussen wrote:
> Well, I guess I can get away with it by using eval for the most esoteric 
> stuff.

That is almost certainly the wrong solution.  90% is the time when
people want to use eval it is the wrong think to do.  (Number taken
out of the air.  But certainly eval is often misused.)  Use eval to
evaluate an expression from an external source - such as a user
typing an expression in a form.  And that's all.

Eval breaks lexical scoping, error checking, compiler optimization,
modules, etc.

> Is the code below safe?

> (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.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/



More information about the Kawa mailing list