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


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/


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