I was wondering if anyone has tried somehow calling Jython functions
from within Clojure, and how you went about doing this if so. I have
not used Jython, but I would imagine the Jython interpreter can be
invoked in the same way as any other java code, and Python programs
can be run within it. However I wonder if it would be possible to
somehow call individual python functions from Clojure. Like I said, I
have not tried this yet, so it might actually be straightforward and
obvious. I'm just wondering if anyone has tried doing this.
Thanks,
Rob
I haven't tried it, but the strategies for executing Jython code from
Java should work at least as well from Clojure. There are two
approaches.
One approach is to compile the Jython code into a class file. This
requires some work on the Python side (similar to using gen-class in
Clojure so that Clojure code can be called from Java), and the Python
class of interest can't use multiple-inheritance. This approach is
discussed in the section called "How to create Jython classes callable
from Java programs" at
http://www.seanet.com/~bugbee/python/jython4.html
Another approach is to invoke the Jython interpreter as you suggested,
load a Python script, and ask the interpreter to evaluate a function
for you. An example can be found in this page:
http://bytes.com/topic/python/answers/22390-executing-jython-function-java
Additional discussion about the second approach can be found in the
section called "How to run Python programs from Java" at
http://www.seanet.com/~bugbee/python/jython4.html
The procedure I've used most with Jython (and found to be quite
robust) is to define an interface in Java, and then implement (extend)
that interface in Jython. Then just create an instance of that object
with JythonInterpreter, and you get a valid Java object implementing
your interface. Here's some description on that topic:
http://jythonpodcast.hostjava.net/jythonbook/chapter10.html
I haven't actually tried to combine it with Clojure, but with this
"interface approach" it should be a cakewalk, since Clojure calls to
Java are direct with no "magic translation layers". Calling Clojure
from Jython could be a bit trickier, though, since Jython has these
translation layers.
Best Regards,
Joonas
One approach is to compile the Jython code into a class file. This
requires some work on the Python side (similar to using gen-class in
Clojure so that Clojure code can be called from Java), and the Python
class of interest can't use multiple-inheritance. This approach is
discussed in the section called "How to create Jython classes callable
from Java programs" at
http://www.seanet.com/~bugbee/python/jython4.html
Rob
On Jan 24, 7:08 pm, Eric Lavigne <lavigne.e...@gmail.com> wrote:
> > I was wondering if anyone has tried somehow calling Jython functions
> > from within Clojure, and how you went about doing this if so. I have
> > not used Jython, but I would imagine the Jython interpreter can be
> > invoked in the same way as any other java code, and Python programs
> > can be run within it. However I wonder if it would be possible to
> > somehow call individual python functions from Clojure. Like I said, I
> > have not tried this yet, so it might actually be straightforward and
> > obvious. I'm just wondering if anyone has tried doing this.
>
> I haven't tried it, but the strategies for executing Jython code from
> Java should work at least as well from Clojure. There are two
> approaches.
>
> One approach is to compile the Jython code into a class file. This
> requires some work on the Python side (similar to using gen-class in
> Clojure so that Clojure code can be called from Java), and the Python
> class of interest can't use multiple-inheritance. This approach is
> discussed in the section called "How to create Jython classes callable
> from Java programs" athttp://www.seanet.com/~bugbee/python/jython4.html
>
> Another approach is to invoke the Jython interpreter as you suggested,
> load a Python script, and ask the interpreter to evaluate a function
> for you. An example can be found in this page:http://bytes.com/topic/python/answers/22390-executing-jython-function...
Thank you for these good ideas! I'm going to try it. My goal is to
use the Natural Language Toolkit in Clojure. I also posted the same
question here: http://stackoverflow.com/questions/2129253/clojure-jython-interop
Rob
> from Java programs" athttp://www.seanet.com/~bugbee/python/jython4.html
On Jan 24, 7:08 pm, Eric Lavigne <lavigne.e...@gmail.com> wrote:
> > I was wondering if anyone has tried somehow calling Jython functions
> > from within Clojure, and how you went about doing this if so. I have
> > not used Jython, but I would imagine the Jython interpreter can be
> > invoked in the same way as any other java code, and Python programs
> > can be run within it. However I wonder if it would be possible to
> > somehow call individual python functions from Clojure. Like I said, I
> > have not tried this yet, so it might actually be straightforward and
> > obvious. I'm just wondering if anyone has tried doing this.
>
> I haven't tried it, but the strategies for executing Jython code from
> Java should work at least as well from Clojure. There are two
> approaches.
>
> One approach is to compile the Jython code into a class file. This
> requires some work on the Python side (similar to using gen-class in
> Clojure so that Clojure code can be called from Java), and the Python
> class of interest can't use multiple-inheritance. This approach is
> discussed in the section called "How to create Jython classes callable
>> for you. An example can be found in this page:http://bytes.com/topic/python/answers/22390-executing-jython-function...
> Another approach is to invoke the Jython interpreter as you suggested,
> load a Python script, and ask the interpreter to evaluate a function
>> section called "How to run Python programs from Java" athttp://www.seanet.com/~bugbee/python/jython4.html
> Additional discussion about the second approach can be found in the
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
On Jan 25, 2:41 pm, Marc Downie <m...@openendedgroup.com> wrote:
> > clojure+u...@googlegroups.com<clojure%2Bunsu...@googlegroups.com>
http://code.google.com/p/clojure-python/source/browse/trunk/
http://code.google.com/p/clojure-python/source/browse/trunk/src/python.clj
Let me know what you think, feedback, suggestions, contributions, etc.
Rob
On Jan 25, 6:31 pm, rob <r.p.l...@gmail.com> wrote:
> Thanks again Marc, I made a note of it on the StackOverflow thread.
>
> On Jan 25, 2:41 pm, Marc Downie <m...@openendedgroup.com> wrote:
>
>
>
> > On Mon, Jan 25, 2010 at 5:34 PM, rob <r.p.l...@gmail.com> wrote:
> > > Thank you for these good ideas! I'm going to try it. My goal is to
> > > use the Natural Language Toolkit inClojure. I also posted the same
> > > question here:
> > >http://stackoverflow.com/questions/2129253/clojure-jython-interop
>
> > Since NLTK is variously just bunch functions, or classes without any java
> > interface counterpart (because it's a pure Python library, it doesn't know
> > anything about Java), I'm afraid you really are looking at the kind of
> > things that I wrote in my first email. (The leading answer on stackoverflow
> > seems technically correct, but misses the Py.java2py and .__tojava__
> > convenience calls, and has a go at to recoding part of them inClojure).
>
> > have fun (and do let me know when you come up with something tighter than
> > what I wrote).
>
> > best,
>
> > Marc.
>
> > > Rob
>
> > > On Jan 24, 7:08 pm, Eric Lavigne <lavigne.e...@gmail.com> wrote:
> > > > > I was wondering if anyone has tried somehow callingJythonfunctions
> > > > > from withinClojure, and how you went about doing this if so. I have
> > > > > not usedJython, but I would imagine theJythoninterpreter can be
> > > > > invoked in the same way as any other java code, and Python programs
> > > > > can be run within it. However I wonder if it would be possible to
> > > > > somehow call individual python functions fromClojure. Like I said, I
> > > > > have not tried this yet, so it might actually be straightforward and
> > > > > obvious. I'm just wondering if anyone has tried doing this.
>
> > > > I haven't tried it, but the strategies for executingJythoncode from
> > > > Java should work at least as well fromClojure. There are two
> > > > approaches.
>
> > > > One approach is to compile theJythoncode into a class file. This
> > > > requires some work on the Python side (similar to using gen-class in
> > > >Clojureso thatClojurecode can be called from Java), and the Python
> > > > class of interest can't use multiple-inheritance. This approach is
> > > > discussed in the section called "How to createJythonclasses callable
> > > > from Java programs" athttp://www.seanet.com/~bugbee/python/jython4.html
>
> > > > Another approach is to invoke theJythoninterpreter as you suggested,
> > > > load a Python script, and ask the interpreter to evaluate a function
> > > > for you. An example can be found in this page:
> > >http://bytes.com/topic/python/answers/22390-executing-jython-function...
>
> > > > Additional discussion about the second approach can be found in the
> > > > section called "How to run Python programs from Java" athttp://
> > >www.seanet.com/~bugbee/python/jython4.html
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Clojure" group.
> > > To post to this group, send email tocl...@googlegroups.com