public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* calling scheme procedure from java and passing a list as argument...
@ 2015-09-17 13:09 Damien Mattei
  2015-09-17 18:54 ` Per Bothner
  0 siblings, 1 reply; 4+ messages in thread
From: Damien Mattei @ 2015-09-17 13:09 UTC (permalink / raw)
  To: kawa

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

thanks
Damien

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: calling scheme procedure from java and passing a list as argument...
  2015-09-17 13:09 calling scheme procedure from java and passing a list as argument Damien Mattei
@ 2015-09-17 18:54 ` Per Bothner
  2015-09-18  9:53   ` Damien Mattei
  0 siblings, 1 reply; 4+ messages in thread
From: Per Bothner @ 2015-09-17 18:54 UTC (permalink / raw)
  To: Damien Mattei, kawa



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.
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: calling scheme procedure from java and passing a list as argument...
  2015-09-17 18:54 ` Per Bothner
@ 2015-09-18  9:53   ` Damien Mattei
  2015-09-18 13:51     ` Damien Mattei
  0 siblings, 1 reply; 4+ messages in thread
From: Damien Mattei @ 2015-09-18  9:53 UTC (permalink / raw)
  To: Per Bothner, kawa



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...



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: calling scheme procedure from java and passing a list as argument...
  2015-09-18  9:53   ` Damien Mattei
@ 2015-09-18 13:51     ` Damien Mattei
  0 siblings, 0 replies; 4+ messages in thread
From: Damien Mattei @ 2015-09-18 13:51 UTC (permalink / raw)
  To: kawa

finally i understand my error,result of many years without coding in java...

here is the solution:

    LList glst = new LList();
    //glst = glst.list2(2,3); // works also
    glst = LList.list2(2,3);
    System.out.println("glst : "+glst);
    Object result0 = vec.plus(glst);
    System.out.println("result0 :"+result0);


    Pair pair = new Pair(2, LList.Empty);
    Pair pair2 = new Pair(3, pair);
    LList glst2 = new LList();
    glst2 = pair2;
    System.out.println("glst2 : "+glst2);
    Object result = vec.plus(glst2);
    System.out.println("result : "+result);

and the result:

glst : (2 3)
result0 :5
glst2 : (3 2)
result : 5

Le 18/09/2015 11:52, Damien Mattei a écrit :
>
> 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...
>
>
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-09-18 13:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-17 13:09 calling scheme procedure from java and passing a list as argument Damien Mattei
2015-09-17 18:54 ` Per Bothner
2015-09-18  9:53   ` Damien Mattei
2015-09-18 13:51     ` Damien Mattei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).