Mathematica like eval
Hi all, I'm a novice to Clojure (but not to programming). I'm looking for an implementation of an eval function to eval expression like Mathematica does. For instance, in Mathematica the expression: 8 + a + 9 (2 + b) + 2 if a and b are not bound, translates to Plus[10, a, Times[9, Plus[2, b]]] if a and b become bounded later (let say to 1 and 2) and the expression is evaluated again, it returns 47. I would like to be able to run: (eval-partial '(+ (+ 8 2) a (* 9 (+ 2 b and get, if a and b are unbound: (fn [x y] (+ 10 x (* 9 (+ 2 y or (better still) ['(a b) (fn [x y] (+ 10 x (* 9 (+ 2 y] Notice that, whenever possible, the eval takes place and parts of the expression are evaluated (in the example above, the expression (+ 8 2) is evaluated to 10). If you know of any implementation or have any ideas on the subject, please let me know. Cheers, Dilvan. -- 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 - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Mathematica like eval
Hi, Thanks for both answers. I will try to find the relevant text in Joy of Clojure (I have access to the first edition). I followed the expresso <https://github.com/clojure-numerics/expresso> link, but I am not interested in mathematical expressions. Refining my question: I am more interested in the programming aspects of Mathematica (or to its descendant Wolfram Language). In the eval case, a better example would be (a is unbound): (def b 1) (eval-partial '(+ (+ 8 2) a (* 9 (+ 2 b --> '(+ 37 a) Eval-partial would return a Lisp expression with unbound symbols. The expression being evaluated could be quite complex. With eval-partial, I would like to be able to have complex functions that depend on results that aren't ready yet. They would evaluate (partially) to expressions that could be re-evaluated later, to see if all the symbols they depend upon are ready (bound). I intend to use this technique to write more flexible DSLs. BTW, if expresso can do some similar to this, I am willing to give it a second look. Any ideas? Cheers, Dilvan. On Friday, June 13, 2014 6:46:56 PM UTC-3, Dilvan wrote: > >Hi all, > >I'm a novice to Clojure (but not to programming). >I'm looking for an implementation of an eval function to eval > expression like Mathematica does. >For instance, in Mathematica the expression: > >8 + a + 9 (2 + b) + 2 > >if a and b are not bound, translates to > > Plus[10, a, Times[9, Plus[2, b]]] > >if a and b become bounded later (let say to 1 and 2) and the expression > is evaluated again, it returns 47. > >I would like to be able to run: > (eval-partial '(+ (+ 8 2) a (* 9 (+ 2 b >and get, if a and b are unbound: > (fn [x y] (+ 10 x (* 9 (+ 2 y >or (better still) > ['(a b) (fn [x y] (+ 10 x (* 9 (+ 2 y] >Notice that, whenever possible, the eval takes place and parts of the > expression are evaluated (in the example above, the expression (+ 8 2) is > evaluated to 10). > >If you know of any implementation or have any ideas on the subject, > please let me know. > >Cheers, > Dilvan. > > -- 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 - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Jython Interoperability problem
Hi, It was possible in clojure 1.0.0 to include clojure Persistent collections in Jython: jython -Dpython.path=/clojure_1.0.0/clojure-1.0.0.jar >>>from clojure.lang import PersistentList >>>b= PersistentList.create([7, 8, 2]) >>>b (7 8 2) But with clojure 1.1.0 or 1.2.0 I get: jython -Dpython.path=/clojure-1.2.0/clojure.jar >>> from clojure.lang import PersistentList >>> b= PersistentList.create([7, 8, 2]) >>> b Traceback (most recent call last): File "", line 1, in java.lang.ExceptionInInitializerError at clojure.lang.ASeq.toString(ASeq.java:20) at org.python.core.PyJavaType$5.__call__(PyJavaType.java:542) at org.python.core.PyObjectDerived.__repr__(PyObjectDerived.java:63) at org.python.core.PySystemState.displayhook(PySystemState.java:1190) at org.python.core.PySystemStateFunctions.__call__(PySystemState.java: 1257) at org.python.core.PyObject.invoke(PyObject.java:3583) at org.python.core.Py.printResult(Py.java:1748) at org.python.pycode._pyx5.f$0(:1) at org.python.pycode._pyx5.call_function() at org.python.core.PyTableCode.call(PyTableCode.java:165) at org.python.core.PyCode.call(PyCode.java:18) at org.python.core.Py.runCode(Py.java:1204) at org.python.core.Py.exec(Py.java:1248) at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:181) at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java: 89) at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java: 70) at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java: 46) at org.python.util.InteractiveConsole.push(InteractiveConsole.java: 110) at org.python.util.InteractiveConsole.interact(InteractiveConsole.java: 90) at org.python.util.jython.run(jython.java:316) at org.python.util.jython.main(jython.java:129) Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: Could not locate clojure/core__init.class or clojure/core.clj on classpath: at clojure.lang.RT.(RT.java:305) ... 21 more Caused by: java.io.FileNotFoundException: Could not locate clojure/ core__init.class or clojure/core.clj on classpath: at clojure.lang.RT.load(RT.java:412) at clojure.lang.RT.load(RT.java:381) at clojure.lang.RT.doInit(RT.java:416) at clojure.lang.RT.(RT.java:302) ... 21 more java.lang.ExceptionInInitializerError: java.lang.ExceptionInInitializerError Any clues? -- 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 - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Jython Interoperability problem
Hi, Thanks a lot for your reply. I thought Java interoperability was one of the key points for Clojure "a language for the JVM", having a pure Clojure version that limits interoperability in the JVM isn't quite in this spirit. The first project (clj-ds) seems quite what I need now, but I would like to be able to use the libraries shipped with Clojure. They are more likely to be around for the long run. Do you know how can I "bootstrap" Clojure before using any Clojure specific data structure (from Java or Jython)? The 1 second start-up time and slower performance for large structure, when compared to clj-ds, aren't an issue for me right now. On Nov 1, 9:24 pm, Mikhail Kryshen wrote: > Consider using some implementation of persistent data structures that > does not depend on Clojure. > > Clojure's data structures modified for use outside of > Clojure:http://github.com/krukow/clj-ds > > Persistent analogue of the Java Collections > Framework:http://code.google.com/p/pcollections/ > > On Fri, 29 Oct 2010 07:41:17 -0700 (PDT) > > > > Dilvan wrote: > > Hi, > > > It was possible in clojure 1.0.0 to include clojure Persistent > > collections in Jython: > > > jython -Dpython.path=/clojure_1.0.0/clojure-1.0.0.jar > > > >>>from clojure.lang import PersistentList > > >>>b= PersistentList.create([7, 8, 2]) > > >>>b > > (7 8 2) > > > But with clojure 1.1.0 or 1.2.0 I get: > > > jython -Dpython.path=/clojure-1.2.0/clojure.jar > > > >>> from clojure.lang import PersistentList > > >>> b= PersistentList.create([7, 8, 2]) > > >>> b > > Traceback (most recent call last): > > File "", line 1, in > > java.lang.ExceptionInInitializerError > > at clojure.lang.ASeq.toString(ASeq.java:20) > > at org.python.core.PyJavaType$5.__call__(PyJavaType.java:542) > > at org.python.core.PyObjectDerived.__repr__(PyObjectDerived.java:63) > > at org.python.core.PySystemState.displayhook(PySystemState.java:1190) > > at org.python.core.PySystemStateFunctions.__call__(PySystemState.java: > > 1257) > > at org.python.core.PyObject.invoke(PyObject.java:3583) > > at org.python.core.Py.printResult(Py.java:1748) > > at org.python.pycode._pyx5.f$0(:1) > > at org.python.pycode._pyx5.call_function() > > at org.python.core.PyTableCode.call(PyTableCode.java:165) > > at org.python.core.PyCode.call(PyCode.java:18) > > at org.python.core.Py.runCode(Py.java:1204) > > at org.python.core.Py.exec(Py.java:1248) > > at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:181) > > at > > org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java: > > 89) > > at > > org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java: > > 70) > > at > > org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java: > > 46) > > at org.python.util.InteractiveConsole.push(InteractiveConsole.java: > > 110) > > at > > org.python.util.InteractiveConsole.interact(InteractiveConsole.java: > > 90) > > at org.python.util.jython.run(jython.java:316) > > at org.python.util.jython.main(jython.java:129) > > Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: > > Could not locate clojure/core__init.class or clojure/core.clj on > > classpath: > > at clojure.lang.RT.(RT.java:305) > > ... 21 more > > Caused by: java.io.FileNotFoundException: Could not locate clojure/ > > core__init.class or clojure/core.clj on classpath: > > at clojure.lang.RT.load(RT.java:412) > > at clojure.lang.RT.load(RT.java:381) > > at clojure.lang.RT.doInit(RT.java:416) > > at clojure.lang.RT.(RT.java:302) > > ... 21 more > > > java.lang.ExceptionInInitializerError: > > java.lang.ExceptionInInitializerError > > > Any clues? > > -- > Mikhail -- 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 - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Jython Interoperability problem
On Nov 1, 9:24 pm, Mikhail Kryshen wrote: > Clojure's data structures modified for use outside of > Clojure:http://github.com/krukow/clj-ds > > Persistent analogue of the Java Collections > >Framework:http://code.google.com/p/pcollections/ These libraries only cover persistent collections (lists, hashtables, etc). I am also using clojure.lang.Ref class (to implement STMs). Are there any libraries that implement clojure.lang.Ref outside Clojure? Or does anyone knows how to "bootstrap" Clojure before creating any object from a persistent collection class? Ref objects seem to be working without any need for a "bootstrap". -- Dilvan Moreira http://java.icmc.usp.brdil...@icmc.usp.br -- 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 - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Jython Interoperability problem
Thanks, it works for me. On Nov 21, 1:11 am, Alex Osborne wrote: > Dilvan writes: > > Do you know how can I "bootstrap" Clojure before using any Clojure > > specific data structure (from Java or Jython)? > > It seems to be fine if you put it on the Java system classpath instead > of python.path: > > $ jython -J-cp clojure-1.2.0.jar > Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54) > [Java HotSpot(TM) 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_22 > Type "help", "copyright", "credits" or "license" for more information.>>> > from clojure.lang import PersistentList > >>> b= PersistentList.create([7, 8, 2]) > >>> b > > (7 8 2) -- 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 - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Reusing Clojure libraries in Java/Jythom/Scala
Hi, During the discussions of the topic "Jython Interoperability problem", Mikhail Kryshen suggested implementations of Clojure data structures outside Clojure: >Clojure's data structures modified for use outside of Clojure: >http://github.com/krukow/clj-ds >Persistent analogue of the Java Collections Framework: >http://code.google.com/p/pcollections/ I've been using the Clojure libraries (immutable collections and Refs) in Java programs (a version of the Manchester OWL-API). Reading the documentation for the Clojure replacements suggested by Mikhail, they imply that the implementations inside the official Clojure libraries are inefficient (in terms of speed and memory) if used in Java only applications (no Clojure code) AND that, in the future, they may demand that all of the Clojure machinery be loaded with them. Is there any official view/police about this issue? The question I need to answer is: Should I keep using the Clojure libraries in my programs or migrate them to some other implementation of immutable collections + Refs (STM) + (maybe) actors? Advices are welcomed :-) DIlvan Moreira -- 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 - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Reusing Clojure libraries in Java/Jythom/Scala
Hi, From today, I will not receive updates from this group, so if anyone cares to answer this question, please send me an email: dil...@gmail.com. I do think that this is an important question to many people that liked a lot the Clojure concurrency model but cannot use Clojure in their day to day programs. Cheers, Dilvan On Nov 22, 12:58 pm, Dilvan wrote: > Hi, > > During the discussions of the topic "Jython Interoperability > problem", > Mikhail Kryshen suggested implementations of Clojure data structures > outside Clojure: > > >Clojure's data structures modified for use outside of Clojure: > >http://github.com/krukow/clj-ds > >Persistent analogue of the Java Collections Framework: > >http://code.google.com/p/pcollections/ > > I've been using the Clojure libraries (immutable collections and > Refs) in Java programs (a version of the Manchester OWL-API). Reading > the documentation for the Clojure replacements suggested by Mikhail, > they imply that the implementations inside the official Clojure > libraries are inefficient (in terms of speed and memory) if used in > Java only applications (no Clojure code) AND that, in the future, they > may demand that all of the Clojure machinery be loaded with them. Is > there any official view/police about this issue? > > The question I need to answer is: Should I keep using the Clojure > libraries in my programs or migrate them to some other implementation > of immutable collections + Refs (STM) + (maybe) actors? > > Advices are welcomed :-) > > DIlvanMoreira -- 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 - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en