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]

define-procedure with several lambda forms?


Hi,

I'm having trouble with define-procedure when trying to define more than a method.
BTW, define-procedure remembers me of Oaklisp (add-method) and the T dialect of Lisp.

It looks like only the first lambda is processed, not the second one.

HTML: ...kawa/Procedures.html#Procedures

;; to operate on integers, byte[], u8vector and more
(define-procedure encode+base64
  method: (lambda ((v :: <u8vector>))
    ;;(encode+base64 (u8vector->bytes v))
    123
    )
  method: (lambda ((bytes :: <byte[]>))
    (Base64:encode bytes))
)
[method: is optional, but it doesn't work better if omitted.]

;;(encode+base64 #u8(1 2 3)) -> 123 [the first lambda works]
;;(encode+base64 (Base64:decode "ABCD"))
Argument #0 to 'lambda' has wrong type
	at gnu.mapping.WrongType.make(WrongType.java:56)
	at atInteractiveLevel.apply1(Unknown Source)
	at gnu.expr.ModuleBody.applyN(ModuleBody.java:171)
	at gnu.expr.ModuleMethod.applyN(ModuleMethod.java:105)
	at gnu.expr.ModuleMethod.applyV(ModuleMethod.java:133)
	at gnu.expr.GenericProc.applyN(GenericProc.java:70)
	at gnu.mapping.Procedure.apply(Procedure.java:102)
	at gnu.mapping.CallContext.runUntilDone(CallContext.java:258)
	at gnu.expr.ModuleExp.evalModule(ModuleExp.java:188)
	at kawa.Shell.run(Shell.java:232)
	at kawa.Shell.run(Shell.java:180)
	at kawa.Shell.run(Shell.java:167)
	at kawa.Shell.run(Shell.java:154)
	at kawa.repl.main(repl.java:609)
Caused by: java.lang.ClassCastException
	... 13 more
[transposing both method definitions lead me to conclude that only the first lambda ever works].

I also tried make-procedure, with the same errors.

You may be interested in
(define (u8vector->bytes v)
  ;; This ought to be in Kawa as simply an accessor!
  (let* ((len (u8vector-length v))
	 (bytes ((primitive-array-new <byte>) len)))
    (let loop ((i 0) (j len))
      (cond
       ((zero? j) bytes)
       (else
	((primitive-array-set <byte>) bytes i
	 (u8vector-ref v i))
	(loop (+ i 1) (- j 1)))))))
;(u8vector->bytes #u8(3 2 1))

; hijacking base64 code from Xerces:
(define-namespace Base64 "class:org.apache.xerces.impl.dv.util.Base64")

Thanks for your help,
	Jorg Hohle.


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