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: Problem with macro expansion


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/


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