Re: Calling Clojure *from* Java

2019-06-10 Thread Howard Lewis Ship
like, 2012) to generate the bytecode on the fly. On Sun, Jun 9, 2019 at 9:25 PM eglue wrote: > Regarding calling Clojure **from** Java... > > I saw a Stuart Halloway tweet responding to someone who'd found this a > "soul-crushing, miserable experience." > > I had a

Calling Clojure *from* Java

2019-06-09 Thread eglue
Regarding calling Clojure **from** Java... I saw a Stuart Halloway tweet responding to someone who'd found this a "soul-crushing, miserable experience." I had a similar miserable experience and figured it was just me, but am now suspecting that's not the case. (Happy t

Re: Best practice for calling Clojure from Java

2016-05-02 Thread Patrick Martin
re layer would >>>> allow interaction with this system dynamically. I am designing a Clojure >>>> DSL that would allow a user to load new functions and deploy them live >>>> into >>>> the Java framework. My current design is to push a Clojure

Re: Best practice for calling Clojure from Java

2016-05-01 Thread Howard Lewis Ship
> the Java framework. My current design is to push a Clojure function string >>> into the Java layer and use the guidance from this post to execute: >>> http://stackoverflow.com/questions/2181774/calling-clojure-from-java/23555959#23555959 >>> >>> Here is a gis

Re: Best practice for calling Clojure from Java

2016-05-01 Thread Timothy Baldridge
nto the Java >> framework. My current design is to push a Clojure function string into the >> Java layer and use the guidance from this post to execute: >> http://stackoverflow.com/questions/2181774/calling-clojure-from-java/23555959#23555959 >> >

Re: Best practice for calling Clojure from Java

2016-05-01 Thread Timothy Baldridge
to load new functions and deploy them live into the Java > framework. My current design is to push a Clojure function string into the > Java layer and use the guidance from this post to execute: > http://stackoverflow.com/questions/2181774/calling-clojure-from-java/23555959#23555959 > > H

Best practice for calling Clojure from Java

2016-05-01 Thread Patrick Martin
the Java framework. My current design is to push a Clojure function string into the Java layer and use the guidance from this post to execute: http://stackoverflow.com/questions/2181774/calling-clojure-from-java/23555959#23555959 Here is a gist example based on that thread: https

Re: Calling Clojure from Java and classloader

2012-06-15 Thread Warren Lynn
clojure code from java is through RT. An example > would be the accepted answer here: > http://stackoverflow.com/questions/2181774/calling-clojure-from-java > > I really don't like the RT way (very clumsy), so I want to avoid it if possible. My .jar file will include Clojure itse

Re: Calling Clojure from Java and classloader

2012-06-15 Thread Aaron Cohen
OT your code and then directly try to use it from java. The generated java bytecode isn't guaranteed to be stable across versions of clojure, and you're depending on implementation details. One way to use your clojure code from java is through RT. An example would be the accepted answer

Calling Clojure from Java and classloader

2012-06-13 Thread Warren Lynn
Ok, I hit a wall and really did not see this coming. Based on what I have read, its really easy for Clojure and Java to work together. So I wrote some test Clojure code with a very simple defrecord (say named as "testrec") and AOT compile it, create a jar file, and add it to a "HelloWorld" java pr

Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread raschedh
Ah, cool ! Thank you very much for this insider knowledge, Mr. Sierra !!! Great. That means more clojure in production. Hurrah !!! Thanks again. Heinz. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@goo

Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread Stuart Sierra
Yes, Clojure has a "runtime" which is initialized the first time you call any Clojure code. The initialization never happens more than once. -S -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegrou

Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread Softaddicts
It's the time to get all the related classes loaded needed to support the Clojure code and yes it's a one time cost. The first reference to x gets this triggered. Luc > The following makes it clearer: > > package e; > > > > import p.x; > > > > public final class E { > >public static void m

Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread raschedh
The following makes it clearer: package e; > > import p.x; > > public final class E { >public static void main(String[] args) { > System.out.println("before"); > for (int i = 0; i < 100; ++i) { > System.out.println(x.f()); > } > } > > Now: After launching, the string `be

Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread raschedh
> > Hm. I do have the feeling, that we do not understand each other. Code is always unambigous. I give an example, and give my question another run. (ns p.x (:gen-class :methods [ ^{:static true} [f [] String] ])) (defn -f [] "hello, world") Fire up a REPL, make sure, p/x.clj is in your cla

Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread Softaddicts
Compared to Java, not noticeable if any. We run our app in production on cluster of small computers. We replaced component written mostly in Java by Clojure equivalents without any degradation in service time. We used clojure from java a number of times using Java callable interfaces generated in

Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread raschedh
Yes, I do compile my clojure code ahead of time (AOT) to byte code. Does that mean, that your, ahead of time compiled clojure code, has no noticeable delay, when you first call it ? If in the middle of the lifetime of an app, this delay happens, i can not consider it small, if 1 requests are

Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread Softaddicts
Ah, do you compile your Clojure code to Java prior to using it (AOT compilation) ? If not, you must add the clojure compilation time to spit out the class(es) byte code. Here we deliver AOTed components so there's no compilation overhead, we do this for other reasons than this very small overhea

Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread raschedh
Thank you, for your answer. It doesn't convince me, though. I am well aware of the class loading mechanism of the JVM. But if I compile against, say guava-12.0.jar (beautiful stuff by the way), and use those classes at runtime, there is no delay in using them whatsoever. At least not a delay of

Re: does delay in calling clojure from java happen only once ?

2012-05-17 Thread Softaddicts
question. > > My experiments lead me to the conjecture, that > the answer is yes. > But a proof can only be given by someone, > who is familiar with clojure's implementation of which I > have no clue. > > Thanks for your help !: > > The question is concerned w

does delay in calling clojure from java happen only once ?

2012-05-17 Thread raschedh
which I have no clue. Thanks for your help !: The question is concerned with calling clojure from Java. I have a bunch of clojure stuff, which I compiled to byte code with the techniques described at http://clojure.org/compilation I made an archive A of the result. I have Java code, that uses t

Re: Calling clojure from java.

2011-07-28 Thread Ken Wesson
On Thu, Jul 28, 2011 at 1:58 PM, Meikel Brandmeyer wrote: > If the thing you want to call is a macro, you have to hope that the library > other provided the logic as star function (as in Nicolas' case). If there is > no function containing the actual logic, you have to re-implement the macro >

Re: Calling clojure from java.

2011-07-28 Thread Meikel Brandmeyer
Hi, Am 28.07.2011 um 19:43 schrieb mmwaikar: > Thanks again Meikel. Where can I read about things like bindRoot, intern or > to be precise java-clojure interop? There are only a few things you must know: - RT.var to get a variable from a namespace - v.invoke to invoke a function stored in a Va

Re: Calling clojure from java.

2011-07-28 Thread .Bill Smith
It may also be useful to read up on primitives, since primitive support is often a source of impedance mismatch when software in one language talks to software in another. Would someone mind supplying a link to a description of how Clojure works with Java primitives in the 1.2.1 and 1.3 release

Re: Calling clojure from java.

2011-07-28 Thread mmwaikar
Thanks again Meikel. Where can I read about things like bindRoot, intern or to be precise java-clojure interop? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new mem

Re: Calling clojure from java.

2011-07-26 Thread Meikel Brandmeyer
Hi, Am 26.07.2011 um 19:48 schrieb mmwaikar: > RT.load("lobos/core", true); > RT.load("lobos/schema", true); You should go through require.invoke(). Not RT.load(). > and called wrapper.createTable() then I get - (# lobos.core$create_STAR_@49431028> (quote {:classname "or

Re: Aw: Calling clojure from java.

2011-07-26 Thread mmwaikar
Thanks Meikel, I tried the below stuff - package com.codionics.flyway; import clojure.lang.RT; import clojure.lang.Var; public class wrapper { static final Var symbol = RT.var("clojure.core", "symbol"); static final Var require = RT.var("clojrue.core", "require"); static final Var k

Re: Calling clojure from java.

2011-07-25 Thread Petr Gladkikh
On Tue, Jul 26, 2011 at 12:43 PM, mmwaikar wrote: > Hi, > > I am using the Lobos library - https://github.com/budu/lobos > In it there's a function create, which is called like this - (create db > (table :some-name)), where db is earlier defined as - (def db > {:classname "org.postgresql.Driv

Aw: Calling clojure from java.

2011-07-25 Thread Meikel Brandmeyer
Hi, you should go through the normal Clojure Vars to access the functions. To actually call the functions you use invoke. Note: table is a macro, so you can't call it directly. You have to use the table* function and do any sugar provided by the table macro yourself. Here is an example how this

Calling clojure from java.

2011-07-25 Thread mmwaikar
Hi, I am using the Lobos library - https://github.com/budu/lobos In it there's a function create, which is called like this - (create db (table :some-name)), where db is earlier defined as - (def db {:classname "org.postgresql.Driver" :subprotocol "postgresql" :user "postgres"

Re: Calling Clojure from Java: unbound function

2011-03-28 Thread Mark Meyer
Nope. I moved the main code to ns hexadoku.core (generating package hexadoku, class core) and did the deftype in hexadoku (generating package hexadoku, class HexSolver). The error remains Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Var hexadoku.core/search is unbound. a

Re: Calling Clojure from Java: unbound function

2011-03-28 Thread Ken Wesson
On Mon, Mar 28, 2011 at 8:46 AM, Mark Meyer wrote: > Hi. > I'm having problems calling clojure code from Java. Basically I deftype'd > (deftype HexSolver [] >   Solver >   (solve [this grid] (search (process-grid grid > and somewhere near the top of that file file > (defn search [foo] ...) > t

Calling Clojure from Java: unbound function

2011-03-28 Thread Mark Meyer
Hi. I'm having problems calling clojure code from Java. Basically I deftype'd (deftype HexSolver [] Solver (solve [this grid] (search (process-grid grid and somewhere near the top of that file file (defn search [foo] ...) the very top places this in the namepsace (:ns hexadoku (:gen-cla

Re: Calling Clojure from Java

2010-12-22 Thread Laurent PETIT
2010/12/22 Mark Engelberg > I've decided to go with the old gen-class approach (mainly so I can > take advantage of the "state" option). > I'm running into a problem implementing Iterable. > The following lines in gen-class create a conflict: > :implements [java.lang.Iterable] > :methods [[it

Re: Calling Clojure from Java

2010-12-22 Thread Mark Engelberg
I've decided to go with the old gen-class approach (mainly so I can take advantage of the "state" option). I'm running into a problem implementing Iterable. The following lines in gen-class create a conflict: :implements [java.lang.Iterable] :methods [[iterator [] java.util.Iterator]] It com

Re: Calling Clojure from Java

2010-12-22 Thread Laurent PETIT
2010/12/22 Chas Emerick > > On Dec 22, 2010, at 4:58 AM, Laurent PETIT wrote: > > > There's also this issue raised in the bug tracker (by Chas Emerick I > presume ?) which is about adding a nice java facade for this kind of interop > (and thus also ensuring some independance towards clojure inter

Re: Calling Clojure from Java

2010-12-22 Thread Chas Emerick
On Dec 22, 2010, at 4:58 AM, Laurent PETIT wrote: > There's also this issue raised in the bug tracker (by Chas Emerick I presume > ?) which is about adding a nice java facade for this kind of interop (and > thus also ensuring some independance towards clojure internals). > > What about bringin

Re: Calling Clojure from Java

2010-12-22 Thread Alex Osborne
Mark Engelberg writes: > Looks easy, but your dance and speak methods don't return a value > which leaves a question in my mind... > > If the protocol implementation actually returns a value, do you have > to explicitly typecast it in Java from Object into the desired type? Yep, certainly. A Cl

Re: Calling Clojure from Java

2010-12-22 Thread Laurent PETIT
2010/12/22 Mark Engelberg > Looks easy, but your dance and speak methods don't return a value > which leaves a question in my mind... > > If the protocol implementation actually returns a value, do you have > to explicitly typecast it in Java from Object into the desired type? > Yes -- You rec

Re: Calling Clojure from Java

2010-12-22 Thread Mark Engelberg
Looks easy, but your dance and speak methods don't return a value which leaves a question in my mind... If the protocol implementation actually returns a value, do you have to explicitly typecast it in Java from Object into the desired type? Thanks, Mark -- You received this message because yo

Re: Calling Clojure from Java

2010-12-22 Thread Alex Osborne
Mark Engelberg writes: > Are there any examples available of creating a compiled > class/interface with deftype and defprotocol, and using these from > Java? It's pretty straightforward and works exactly how you might expect it to. Create a new project: $ lein new interop Define a type and

Re: Calling Clojure from Java

2010-12-22 Thread Meikel Brandmeyer
Hi, Am 22.12.2010 um 11:15 schrieb Mark Engelberg: > Are there any examples available of creating a compiled > class/interface with deftype and defprotocol, and using these from > Java? Protocols also define an interface which can be implemented by classes. For deftype this happens when you spe

Re: Calling Clojure from Java

2010-12-22 Thread Mark Engelberg
Are there any examples available of creating a compiled class/interface with deftype and defprotocol, and using these from Java? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that po

Re: Calling Clojure from Java

2010-12-22 Thread Meikel Brandmeyer
Hi, Am 22.12.2010 um 10:56 schrieb Mark Engelberg: > On Wed, Dec 22, 2010 at 1:52 AM, Meikel Brandmeyer wrote: >> It is a little ugly, but works with any function, in particular static and >> protocol functions. If you want a less rough interface, you can still go the >> gen-class route from t

Re: Calling Clojure from Java

2010-12-22 Thread Laurent PETIT
2010/12/22 Mark Engelberg > On Wed, Dec 22, 2010 at 1:52 AM, Meikel Brandmeyer wrote: > > It is a little ugly, but works with any function, in particular static > and protocol functions. If you want a less rough interface, you can still go > the gen-class route from the article. But this will co

Re: Calling Clojure from Java

2010-12-22 Thread Laurent PETIT
gt; http://java.dzone.com/articles/java-clojure-interop-calling > > which dates back to Clojure 1.1. > > > > Seems like a lot of changes have occurred since then -- static > > functions, protocols, etc. So has the "calling Clojure from Java" > > story ch

Re: Calling Clojure from Java

2010-12-22 Thread Mark Engelberg
On Wed, Dec 22, 2010 at 1:52 AM, Meikel Brandmeyer wrote: > It is a little ugly, but works with any function, in particular static and > protocol functions. If you want a less rough interface, you can still go the > gen-class route from the article. But this will come at the cost of one level >

Re: Calling Clojure from Java

2010-12-22 Thread Meikel Brandmeyer
h dates back to Clojure 1.1. > > Seems like a lot of changes have occurred since then -- static > functions, protocols, etc. So has the "calling Clojure from Java" > story changed with Clojure 1.3? If so, can anyone provide pointers to > some recent examples? If you just

Calling Clojure from Java

2010-12-22 Thread Mark Engelberg
then -- static functions, protocols, etc. So has the "calling Clojure from Java" story changed with Clojure 1.3? If so, can anyone provide pointers to some recent examples? Thanks, Mark -- You received this message because you are subscribed to the Google Groups "Clojure" gro

Re: AOT compilation and calling Clojure from Java

2010-08-16 Thread sebastien
Yes, it helped! Thank you! To make the story complete I put here complete code: semantic/hello.clj: (ns semantic.hello (:gen-class :name semantic.hello :methods [[sayhello [] void] [sayhello_arg [String] void]])) (defn -sayhello [this] (println "Hello from Clojure!"))

Re: AOT compilation and calling Clojure from Java

2010-08-16 Thread Wilson MacGyver
you'd import semantic.hello then in your java code, you would first create it by doing new semantic.hello() then you can call it form java by doing .sayhello() without the - you also need to define your sayhello differently I think. it needs to be (defn -sayhello [this] (println "Hello from cl

Re: AOT compilation and calling Clojure from Java

2010-08-15 Thread Meikel Brandmeyer
Hi, On 15 Aug., 21:41, sebastien wrote: > Unfortunetly it doesn't work, pointing to h.hello() and saying "cannot > find symbol". > > Any suggestions? First the method is called sayhello. Not just hello. Then you have to declare the method in the gen-class clause. (ns semantic.hello (:gen-cla

Re: AOT compilation and calling Clojure from Java

2010-08-15 Thread sebastien
I tried to compile hello.clj with "lein compile" and with "(compile 'semantic.hello)", and also with old versions of clojure.jar and clojure.contrib.jar (current one is 1.2-beta1), but it all gave the same result. -- You received this message because you are subscribed to the Google Groups "Cloju

Re: AOT compilation and calling Clojure from Java

2010-08-15 Thread sebastien
> Can you run: > javap YourClass.class > and give us the result? Here it is: public class semantic.hello extends java.lang.Object { public static {}; public semantic.hello(); public java.lang.Object clone(); public int hashCode(); public java.lang.String toString();

Re: AOT compilation and calling Clojure from Java

2010-08-15 Thread Daniel Gagnon
> > > Any suggestions? > > Can you run: javap YourClass.class and give us the result? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - plea

Re: AOT compilation and calling Clojure from Java

2010-08-15 Thread sebastien
Hi Meikel, Unfortunetly it doesn't work, pointing to h.hello() and saying "cannot find symbol". ^ Same with my Eclipse, which says that import "semantic" cannot be resolved, though both package and class are in the bin (classes) directory.

Re: AOT compilation and calling Clojure from Java

2010-08-15 Thread Meikel Brandmeyer
Hi, Am 15.08.2010 um 18:04 schrieb sebastien: > I understand that after AOT compilation Clojure namespaces and > functions became completely normal Java classes and can be called from > any Java code, is it correct? If so, how will look like this call? For > example, I have clojure module: > > (

AOT compilation and calling Clojure from Java

2010-08-15 Thread sebastien
I understand that after AOT compilation Clojure namespaces and functions became completely normal Java classes and can be called from any Java code, is it correct? If so, how will look like this call? For example, I have clojure module: (ns semantic.hello (:gen-class)) (defn -sayhello [] (print

environment when calling clojure from Java

2009-02-23 Thread Thom
I'm new to clojure, and I'm trying to figure out how to integrate it into a somewhat large Java codebase. At a particular point the the program's execution, I'd like to spin up a thread with a swank server on it, but the following code doesn't seem to work. Can I get a pointer from the experienced

Re: Calling Clojure from Java (again)

2009-01-23 Thread lpetit
On 23 jan, 03:00, Stuart Sierra wrote: > On Jan 22, 6:51 pm, Peter Wolf wrote: > > > However, if there is only one Clojure image used for references and the > > like, what happens if someone calls an infinite loop, or infinite > > recursion, in a file.  Does the Clojure server hang/blow up?   >

Re: Calling Clojure from Java (again)

2009-01-23 Thread lpetit
Hi, On 23 jan, 01:43, Peter Wolf wrote: > Hi Laurent, > 1) Does Eclipse use the server for resolving references? Currently, the only resolved references are those that come from a clojure environment launched by the user. So yes. When time comes to resolve references for the needs of the editor

Re: Calling Clojure from Java (again)

2009-01-22 Thread Peter Wolf
Thanks for the explanation Stuart, So it seems that all the Swank Clojure IDEs rely on files only containing "safe" code. I guess that's OK provided everyone understands this. Is is any way to only process the def's? For example processing the following would only define the symbol "foo", b

Re: Calling Clojure from Java (again)

2009-01-22 Thread Stuart Sierra
On Jan 22, 6:51 pm, Peter Wolf wrote: > However, if there is only one Clojure image used for references and the > like, what happens if someone calls an infinite loop, or infinite > recursion, in a file.  Does the Clojure server hang/blow up?   If you code an infinite loop, the SWANK server will

Re: Calling Clojure from Java (again)

2009-01-22 Thread Peter Wolf
Hi Laurent, My questions and current beliefs are: 1) Does Eclipse use the server for resolving references? 2) Is the server visible to the user, or hidden inside Eclipse? 3) Does the server call load-file? 4) Can the user break the server with bogus code in a file? 5) What happens if a file has

Re: Calling Clojure from Java (again)

2009-01-22 Thread lpetit
I'll also reply inline ... -> On 23 jan, 00:51, Peter Wolf wrote: > Thanks for the lengthy reply Laurent,  Replies in-line > > lpetit wrote: > > Peter, > > > We asked us the same question some weeks ago, on clojuredev. > > > We took the path to follow how eclipse launches a java application > >

Re: Calling Clojure from Java (again)

2009-01-22 Thread Peter Wolf
Thanks for the lengthy reply Laurent, Replies in-line lpetit wrote: > Peter, > > We asked us the same question some weeks ago, on clojuredev. > > We took the path to follow how eclipse launches a java application > when the user requires it to test it. > So we created a customized "launch config

Re: Calling Clojure from Java (again)

2009-01-22 Thread lpetit
Peter, We asked us the same question some weeks ago, on clojuredev. We took the path to follow how eclipse launches a java application when the user requires it to test it. So we created a customized "launch configuration" (sorry, eclipse jargon), that is just a classical eclipse java launcher w

Re: Calling Clojure from Java (again)

2009-01-22 Thread Michael Reid
On Thu, Jan 22, 2009 at 4:43 PM, Peter Wolf wrote: > > This is a rejuvenation of the old "calling Java from Clojure" thread > > I have been looking at the solutions from Mark > / > 1) From a Java application, read a text file containing Clojure code > and invoke specific functions it defines

Calling Clojure from Java (again)

2009-01-22 Thread Peter Wolf
This is a rejuvenation of the old "calling Java from Clojure" thread I have been looking at the solutions from Mark / 1) From a Java application, read a text file containing Clojure code and invoke specific functions it defines from Java code. 2) Compile Clojure code to bytecode and use

Re: calling Clojure from Java

2009-01-04 Thread Stuart Sierra
On Jan 3, 8:13 pm, "Mark Volkmann" wrote: > I'd like to learn how to invoke Clojure code from a Java application. > I see at least two options. > > 1) From a Java application, read a text file containing Clojure code > and invoke specific functions it defines from Java code. Here's how I do it:

calling Clojure from Java

2009-01-03 Thread Mark Volkmann
I'd like to learn how to invoke Clojure code from a Java application. I see at least two options. 1) From a Java application, read a text file containing Clojure code and invoke specific functions it defines from Java code. 2) Compile Clojure code to bytecode and use it from a Java application ju