Problem with macro expansion
Per Bothner
per@bothner.com
Wed Dec 2 23:13:00 GMT 2009
On 11/25/2009 01:28 PM, Jamison Hope wrote:
> I encountered a similar problem, where something works in the REPL but
> fails during compilation, attempting to use:
>
> (define-syntax (import-class fqcn)
> (syntax-case fqcn ()
> ((import-class fqcn)
> (let* ((cls :: java.lang.Class (eval (syntax fqcn)))
> (name :: string (java.lang.Class:getSimpleName cls)))
> #`(define-alias ,name ,cls)))))
>
> which is intended to approximate the effect of a Java import.
> ...
> During compilation, even if the define-syntax comes before any usage in
> the file:
> [kawa] java.lang.NullPointerException
> [kawa] at gnu.expr.ReferenceExp.apply(ReferenceExp.java:155)
This was a bug in "eval" of weird scopes (such as happen when
dealing with macros). (Not the eval in the macro - the eval
done by the compiler to expand the syntax-case.)
I just checked in a fix.
Note there were a couple of bugs in your macro - this seems to work:
(define-syntax (import-class form)
(syntax-case form ()
((import-class fqcn)
(let* ((cls :: java.lang.Class (eval (syntax fqcn)))
(name (string->symbol (java.lang.Class:getSimpleName cls))))
#`(define-alias ,(datum->syntax-object form name) fqcn)))))
--
--Per Bothner
per@bothner.com http://per.bothner.com/
More information about the Kawa
mailing list