This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Java classes in Kawa
- From: Chris Bitmead <chris at bitmead dot com>
- To: kawa <kawa at sources dot redhat dot com>
- Date: Thu, 11 Jul 2002 00:14:24 +1000
- Subject: 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).