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]

Java classes in Kawa



I was trying to implement a sort function in kawa. I was hoping to make use of java.util.Collections.sort, so I figured maybe I can write a Kawa class with define-simple-class that inherits java.util.Comparator and implement the interface to implement compare by taking a Scheme function.

(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))))

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

But I'm a bit lost as to the exact incantation I need to make it work.

Is there already a sort function in kawa I've missed? Can I do what I was trying to do with define-simple-class? Can I sort a Scheme List? (I seem to remember that Scheme Lists do implement Java Lists).






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