This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Questions about #!key arguments
- From: Jamison Hope <jrh at theptrgroup dot com>
- To: Kawa mailing list <kawa at sourceware dot org>
- Date: Tue, 25 Oct 2011 15:01:52 -0400
- Subject: Re: Questions about #!key arguments
- References: <4EA7007E.5060903@ipfw.edu>
On Oct 25, 2011, at 2:31 PM, Taylor Venable wrote:
Hi there, I'm trying to use #!key arguments but encountering some
errors.
[...]
#|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
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?
-Jamie
--
Jamison Hope
The PTR Group
www.theptrgroup.com