Note that there are some explanatory texts on larger screens.

plurals
  1. POLisp code called from Java
    primarykey
    data
    text
    <p>Long story:</p> <p>I am doing a project for my functional programing class, and I thought of writing an AI controller in Lisp, for the <a href="http://julian.togelius.com/mariocompetition2009/" rel="noreferrer">Mario AI competition</a>.</p> <p>I was looking over frameworks/libraries/ways of calling Lisp code from Java, or even better Lisp-Java intercommunication. </p> <p>I have looked at <a href="http://jacol.sourceforge.net/" rel="noreferrer">Jacol</a>, but it is old, and it does not compile fine for me. </p> <p>My best choice so far is: <a href="http://jatha.sourceforge.net/" rel="noreferrer">Jatha</a>. It is really neat, although some lisp constructs are not yet implemented, one can easily define his own constructs. For example <strong>mapcar</strong> and <strong>cond</strong> are not implemented. I have implemented my own <strong>mapcar</strong>, named <strong>mapp</strong> in Lisp like this:</p> <pre><code>(defun map* (f l r) (if (null l) r (map* f (rest l) (cons (funcall f (first l)) r)))) (defun mapp (f l) (reverse (map* f l nil))) </code></pre> <p>Now I have a simple function that uses this, for example, a function that numbers how many atoms there are in a non-linear list</p> <pre><code>(defun myfunc (l) (if (atom l) '1 (apply '+ (mapp 'myfunc l)))) (myfunc '(6 2)) </code></pre> <p>This all works fine in <strong>clisp</strong> Now to call Lisp code from Java I used <strong>Jatha</strong>. All one has to do is import the Jatha library in the java project and load a lisp file like this (ex):</p> <pre><code>import org.jatha.*; import org.jatha.dynatype.*; public class Main { public static void main(String[] args) { Jatha lisp = new Jatha(false, false); lisp.init(); lisp.start(); LispValue file = lisp.makeString("X:\\lispproject\\test1.lisp"); LispValue rez1 = lisp.load(file); } } </code></pre> <p>While that code works fine in clisp, and other implementations, this code produces a StackOverflow</p> <p><code> run: APPLY: fn = +, args = ((1 1)) S: ((+ (QUOTE 1) (QUOTE 1))) Exception in thread "main" java.lang.StackOverflowError at java.lang.Long.toString(Long.java:242) at java.lang.Long.toString(Long.java:100) at java.lang.String.valueOf(String.java:2946) at org.jatha.dynatype.StandardLispInteger.toString(StandardLispInteger.java:113) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:152) at org.jatha.dynatype.StandardLispCons.toStringAsCdr_internal(StandardLispCons.java:174) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:153) at org.jatha.dynatype.StandardLispCons.toStringAsCdr_internal(StandardLispCons.java:174) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:153) at org.jatha.dynatype.StandardLispCons.toStringAsCdr_internal(StandardLispCons.java:174) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:153) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:152) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:152) at org.jatha.dynatype.StandardLispCons.toStringAsCdr_internal(StandardLispCons.java:174) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:153) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:152) at org.jatha.dynatype.StandardLispCons.toStringAsCdr_internal(StandardLispCons.java:174) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:153) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:152) at org.jatha.dynatype.StandardLispCons.toStringAsCdr_internal(StandardLispCons.java:174) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:153) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:152) at org.jatha.dynatype.StandardLispCons.toStringAsCdr_internal(StandardLispCons.java:174) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:153) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:152) at org.jatha.dynatype.StandardLispCons.toStringAsCdr_internal(StandardLispCons.java:174) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:153) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:152) at org.jatha.dynatype.StandardLispCons.toStringAsCdr_internal(StandardLispCons.java:174) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:153) at org.jatha.dynatype.StandardLispCons.toString(StandardLispCons.java:152) at org.jatha.dynatype.StandardLispCons.toStringAsCdr_internal(StandardLispCons.java:17 </code></p> <p>So my question is, why does it do this? Is my code wrong? <br/> Is it a bug in Jatha? See for yourself, it doesn't take long to set up. <br/> Have you ever done something similar?<br/> Do you know any other better ways to do this? All I want is to call from Java some Lisp code, get it executed, and get back results computed by the Lisp code. <br/> Thanks.</p> <p>[Edit] Fixed code, pasted something wrong.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload