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: Java classes in Kawa


Hi,

No matter what I try I seem to get "Argument to java.util.Collections.sort has wrong type".
I'm using kawa-cvs. What is wrong?

(define-simple-class <comparator> (<java.util.Comparator>)
(function init-keyword: function:)
((compare (o1 :: <java.lang.Object>) (o2 :: <java.lang.Object>)) :: <int>
((slot-ref (this) 'function) o1 o2)))

(define (sort function list)
(let ((comparator (make <comparator> function: function)))
(invoke-static <java.util.Collections> 'sort list comparator)
list))

(define (comp x1 x2) (cond ((< x1 x2) -1) ((> x1 x2) 1) (else 0)))
(define lu (vector 12 8 7 44 -1 -7 9 8))
(define ls (sort comp lu))
(display ls)


Per Bothner wrote:

Chris Bitmead wrote:

I was trying to implement a sort function in kawa.

The following works to sort vectors:

(define-simple-class <comparator> (<java.util.Comparator>)
(function init-keyword: function:)
((compare (o1 :: <java.lang.Object>) (o2 :: <java.lang.Object>)) :: <int>
((slot-ref (this) 'function) o1 o2)))

(define (sort function list)
(let ((comparator (make <comparator> function: function)))
(invoke-static <java.util.Collections> 'sort list comparator)
list))

(define (comp x1 x2) (cond ((< x1 x2) -1) ((> x1 x2) 1) (else 0)))

(define lu (vector 12 8 7 44 -1 -7 9 8))

(define ls (sort comp lu))

Sorting lists doesn't yet work, because some methods are not
implemented. I'm looking at that now.



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