This is the mail archive of the kawa@sourceware.org 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: calling scheme procedure from java and passing a list as argument...



Le 17/09/2015 20:54, Per Bothner a Ãcrit :
>
>
> On 09/17/2015 06:09 AM, Damien Mattei wrote:
>> hello again,
>> suppose i have a java code (the case is running on tomcat web server but
>> that's make no difference)
>> and i want to pass a list to a scheme routine, i have two questions:
>> -is there a way to call a scheme procedure in kawa,i suppose the answer
>> is yes but how?
>> ( i know i can do it making a method in a kawa class definition and call
>> the method)
>
> This page talks about *evaluating* Scheme from Java:
>
> http://www.gnu.org/software/kawa/Evaluating-Scheme-expressions-from-Java.html
>
>
> If you have a Scheme Proecdure object you can call by using one of the
> apply methods.  For example:
>
>    Object[] args = {x, y};
>    Object result = myProc.applyN(args);
> or:
>   Object result = myProc.apply2(x, y);
>
>> - but how can i pass a list as parameter, what is the equivalent of
>> scheme list in java or kawa??
>> I would greatly appre"ciate a little example...
>
> To create a list you can use one of the static methods in
> gnu..lists.LList,
> like makeList or list1 ... list4.
>
> It's usually best to do as much as you can in Scheme: It is easier (and
> better documented with a more stable API) calling Java from Scheme
> than calling Scheme from Java.
unfortunalely this is a java project including scheme,not the reverse,
i tried to use list2 in this example but it complains that
gnu.lists.LList is not a pair,
in scheme a list is a pair.
i have this error:
Exception in thread "main" Argument #1 '(. #<not a pair>)' to 'car' has
wrong type (gnu.lists.LList) (gnu.lists.LList cannot be cast to
gnu.lists.Pair)
        at Vector2D.plus(Vector2D.scm:28)
        at helloworld.main(helloworld.java:30)
Caused by: java.lang.ClassCastException: gnu.lists.LList cannot be cast
to gnu.lists.Pair
        ... 2 more
when i try to run this code:

    LList glst = new LList();
    glst.list2(2,3);
    Object result = vec.plus(glst);

on this method definition in Vector2D class:
((plus L) ::int
   (+ (car L) (cadr L)))

this is of course for testing before doing serious work...




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