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: Use define-simple-class in macros?


David,

> Ah, that was it! Now if only I could erase my stupidity from 
> the mailing list archive as easily!

At least, your problem reminded me of a problem with macros and Kawa
classes. It does not seem possible to write a hygienic macro that uses
(this):

#|kawa:1|# (define-syntax with-self
             (syntax-rules () 
               ((_ body ...) 
                (let ((self (this)))
                  body ...))))
#|kawa:2|# (define-simple-class <A> (<Object>)
             ((allo) 
              (with-self 
                (format #t "Allo: ~S~%" self))))
<stdin>:10:73: warning - use of 'this' not inside a class
#|kawa:3|# (define a (make <A>))
#|kawa:4|# (invoke a 'allo)
gnu.mapping.UnboundLocationException: unbound location self
        at gnu.mapping.Location.get(Location.java:67)
        at A.allo(<stdin>:12)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at gnu.expr.PrimProcedure.apply(PrimProcedure.java:194)
        at gnu.mapping.CallContext.runUntilDone(CallContext.java:247)
        at gnu.mapping.CallContext.runUntilValue(CallContext.java:311)
        at gnu.mapping.MethodProc.applyN(MethodProc.java:107)
        at gnu.kawa.reflect.Invoke.applyN(Invoke.java:157)
        at gnu.kawa.reflect.Invoke.applyN(Invoke.java:51)
        at gnu.mapping.Procedure.apply(Procedure.java:122)
        at gnu.mapping.Procedure.apply(Procedure.java:114)
        at gnu.mapping.CallContext.runUntilDone(CallContext.java:247)
        at gnu.expr.ModuleExp.evalModule(ModuleExp.java:236)
        at kawa.Shell.run(Shell.java:226)
        at kawa.Shell.run(Shell.java:172)
        at kawa.Shell.run(Shell.java:159)
        at kawa.repl.main(repl.java:673)

If I use define-macro instead, it works:

#|kawa:15|# (define-macro (with-self . args) `(let ((self (this))) ,@args))
#|kawa:16|# (define-simple-class <A> (<Object>)
#|(---:17|#   ((allo) (with-self (format #t "Allo: ~S~%" self))))
#|kawa:18|# (define a (make <A>))
#|kawa:19|# (invoke a 'allo)
Allo: A@bb7759
#|kawa:20|#

This is not a big problem in practice, but it may be worth noting.

Cheers,

Dominique



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