This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: Inter-operating with Java lists
Per Bothner <per@bothner.com> wrote:
> Bhinderwala, Shoeb wrote:
>
> > I have a list of Java objects in a Java list (e.g. java.util.ArrayList).
> > I have a scheme function that takes a Scheme list as a parameter.
> > How do I pass my Java list to the scheme function?
>
> I checked in to CVS an enhancment to LList.makeList to let it
> take any java.util.List.
Another way to do it is to just write a conversion routine from an
ArrayList to a scheme list:
(define-namespace Iterator "class:java.util.Iterator")
(define-namespace Collection "class:java.util.Collection")
(define (collection->list coll)
(iterator->list (Collection:iterator coll)))
(define (iterator->list iter)
(let loop ((acc '()))
(if (Iterator:hasNext iter)
(loop (cons (Iterator:next iter) acc))
(reverse! acc))))
Kawa will generate very efficient code for these procedures.
Regards,
Chris Dean