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: Questions about #!key arguments


On 10/25/2011 03:01 PM, Jamison Hope wrote:
On Oct 25, 2011, at 2:31 PM, Taylor Venable wrote:
#|kawa:30|# (define (foo #!key (code ::int 400) (message ::string
"brrp"))
#|(---:31|# (format #t "code: ~a~%" code)
#|(---:32|# (format #t "message: ~a~%" message))
exception while initializing module atInteractiveLevel$23
at gnu.expr.ModuleContext.findInstance(ModuleContext.java:84)
at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:269)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:180)
at kawa.Shell.run(Shell.java:280)
at kawa.Shell.run(Shell.java:194)
at kawa.Shell.run(Shell.java:175)
at kawa.repl.main(repl.java:884)
Caused by: java.lang.VerifyError: (class: atInteractiveLevel$23,
method: foo$V signature: ([Ljava/lang/Object;)V) Expecting to find
object/array on stack
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2308)
at java.lang.Class.getDeclaredField(Class.java:1897)
at gnu.expr.ModuleContext.findInstance(ModuleContext.java:74)
... 6 more

The problem here isn't a problem with your syntax, it's with the types you're using. Well, one of them, anyway. I don't know if it's documented anywhere, but keyword arguments only work with arguments that are Objects, not primitives. So, when you use int, things blow up. If you change to integer (which is a synonym for the class gnu.math.IntNum), then everything is happy again:

#|kawa:1|# (define (foo #!key (code ::integer 400) (message ::string
"brrp"))
#|(---:2|# (format #t "code: ~a~%" code)
#|(---:3|# (format #t "message: ~a~%" message))
#|kawa:4|# (foo code: 200 message: "asdf")
code: 200
message: asdf

Ah, I see. Thank you very much!


Going back to the first example that works... that's fine when it
stands alone, but if this is inside a define-simple-class I get a
problem when I try to invoke it.

I've never tried to use #!key in class methods, so I can't help you there, sorry. Per?

I should also add that I'm using OpenJDK 6 b22, if that matters or helps.



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