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]

Questions about #!key arguments


Hi there, I'm trying to use #!key arguments but encountering some errors.

This code is OK:



#|kawa:53|# (define (foo #!key (code 400) (message "brrp"))
#|(---:54|#   (format #t "code: ~a~%" code)
#|(---:55|#   (format #t "message: ~a~%" message))
#|kawa:56|# (foo code: 200 message: "asdf")
code: 200
message: asdf



But when I try to add explicit types I get an error:



#|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




Is there something wrong with the way I've declared this? Putting the type at the end gives a different (syntax) error:



#|kawa:36|# (define (foo #!key (code 400 ::int) (message "brrp" ::string))
#|(---:37|# (format #t "code: ~a~%" code)
#|(---:38|# (format #t "message: ~a~%" message))
/dev/stdin:36:20: junk at end of specifier for parameter 'code' after type ::
/dev/stdin:36:20: misformed formals in lambda




Unless I remove the "::" - in which case it gives the same error:



#|kawa:33|# (define (foo #!key (code 400 int) (message "brrp" string))
#|(---:34|# (format #t "code: ~a~%" code)
#|(---:35|# (format #t "message: ~a~%" message))
exception while initializing module atInteractiveLevel$24
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$24, 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




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.



#|kawa:39|# (define-simple-class Example ()
#|(---:40|#    ((foo #!key (code 400) (message "brrp"))
#|(---:41|#      (format #t "code: ~a~%" code)
#|(---:42|#      (format #t "message: ~a~%" message)))
#|kawa:43|# (define ex ::Example (Example))
#|kawa:44|# (ex:foo code: 200 message: "asdf")
java.lang.ArrayIndexOutOfBoundsException: -1
        at gnu.expr.Keyword.searchForKeyword(Keyword.java:114)
        at Example.foo$V(stdin:40)
        at atInteractiveLevel$28.run(stdin:44)
        at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:279)
        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)



Maybe I'm using the #!key wrong? Can they be used for methods? Thanks for any help. All of the above examples are with Kawa 1.11 (revision 7075M) [that is, Subversion trunk] on GNU/Linux x86_64.

--
Taylor ChriÅtopher Venable
Senior Programmer/Analyst
IPFW IT Services KT 204K / 209A
2101 E. Coliseum Blvd.
Fort Wayne, IN 46805
260-481-0720


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