Java classes in Kawa
Per Bothner
per@bothner.com
Fri Dec 20 10:36:00 GMT 2002
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.
--
--Per Bothner
per@bothner.com http://www.bothner.com/per/
More information about the Kawa
mailing list