Re: Java from Scheme from Java

Mario Domenech Goulart <[email protected]> Fri, 28 May 2010 06:15:29 -0400
Newsgroups gmane.comp.java.sisc.user
Message-ID <[email protected]>
Hi Norman

On Fri, 28 May 2010 10:41:45 +0100 Norman Gray <[email protected]> wrote:

> On 2010 May 28, at 02:05, Mario Domenech Goulart wrote:
>
>> I'm working on a Java application which I intend to extend in
>> Scheme.  The application would load a Scheme file, evaluate it
>> and get the result from Scheme to be used by the Java code.  The
>> Scheme code has to be able to call Java code from the
>> application.
>> 
>> I'm having problems to call my Java code from the Scheme code.
>
> I have some code which you might find useful here.  See
> http://code.google.com/p/quaestor/source/browse/#svn/trunk/src/main/org/eurovotech/quaestor
>
> This is an implementation of a web service which can run inside Jetty
> or Tomcat.  That is, it's a Java application which is calling SISC,
> which can in turn (of course) call Java objects.
>
> JettySchemeServer.java and TomcatSchemeServlet.java are the topmost,
> java-facing classes, and SchemeWrapper.java is the bit which joins
> both of those to SISC.  The latter is essentially a number of eval
> methods which can be called from Java to do Scheme work.
>
>> Basically, I want Foo to load bar.scm. bar.scm calls the public
>> `hello' method from Foo.
>
> That's covered.  See the processing of mainScriptName in JettySchemeServer.run()

Thanks for replying and for sharing your code.

With some help from Peter Danenberg on freenode's #scheme I could make
my snippet work.  It seems that the java<->scheme interaction needs some
explicit type conversion that I was not doing (plus the class
instantiation).  The following piece of code works as expected with the
java code from http://paste.lisp.org/display/105704

----------------------------8<------------------------------
(import s2j)
(define-java-classes <foo.Foo>)
(define-generic-java-method %hello)

(define (hello thing)
  (->string (%hello (java-null <foo.Foo>) (->jstring thing))))

(display (hello "world"))
---------------------------->8------------------------------

If there are better ways to do the same thing, please let me know.

Best wishes.
Mario
-- 
http://parenteses.org/mario

------------------------------------------------------------------------------