No eval in ClojureScript!?

900 views
Skip to first unread message

ru

unread,
Feb 13, 2016, 10:25:46 AM2/13/16
to Clojure
Dear ClojureScript users and team!

Without "eval" function ClojureScript can't be recognized as a full-fledged LISP. "Code as data" paradigm can't be implemented without "eval". What purpose of code constructed programmatically, if it can not be evaluated?! In that sence plain old JavaScript is more LISP than ClojureScript. Am I right? May be I have mised something important in that problem?

Sincerely,
  Ru

Daniel Kersten

unread,
Feb 13, 2016, 11:07:36 AM2/13/16
to Clojure
Clojurescript does have eval, in the cljs.js namespace: https://crossclj.info/ns/org.clojure/clojurescript/1.7.228/cljs.js.cljs.html#_eval
Take a look at http://yogthos.net/posts/2015-11-12-ClojureScript-Eval.html for an example and https://swannodette.github.io/2015/07/29/clojurescript-17/ for some more details on dynamic compilation of clojurescript code in clojurescript.

--
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
---
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+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

James Reeves

unread,
Feb 13, 2016, 11:08:11 AM2/13/16
to clo...@googlegroups.com
ClojureScript has cljs.js/eval, which while not as convenient as clojure.core/eval, can accomplish the same effect.

The reason why ClojureScript doesn't have a standard eval is because it adds a huge amount of overhead for relatively little gain. You need to load the entire ClojureScript compiler in your browser. Most of the time that's simply not necessary.

- James

--

ru

unread,
Feb 13, 2016, 11:30:12 AM2/13/16
to Clojure
LISP implementations often have a compiler and an interpreter simulteniously. As I know LISP interpreter is a very simple program and often used as an example in classes. Maybe ClojureScript should include such interpreter for such important task as evaluation of dinamically generated code? 

-Ru

суббота, 13 февраля 2016 г., 18:25:46 UTC+3 пользователь ru написал:

ru

unread,
Feb 13, 2016, 11:39:08 AM2/13/16
to Clojure
All we know that JIT is a Just In Time compiler and that JIT is an important part of Java compiler nowerdays. Maybe JIT ideas can be applied to ClojureScript "eval problem" solution?

-Ru

суббота, 13 февраля 2016 г., 18:25:46 UTC+3 пользователь ru написал:
Dear ClojureScript users and team!

James Reeves

unread,
Feb 13, 2016, 11:53:28 AM2/13/16
to clo...@googlegroups.com
While eval is an important part of Clojure, it's also very rarely used. I've been working with Clojure for almost eight years now, and I've written 60 Clojure libraries. Despite that, I've used eval less than half a dozen times.

Having a way of evaluating ClojureScript in ClojureScript is a nice milestone that shows the maturity of the technology, and it's useful for doing things like writing REPLs and interactive examples. But most of the time it's simply not necessary.

- James

--

ru

unread,
Feb 13, 2016, 12:11:04 PM2/13/16
to Clojure
First thing that comes to my mind is MAXIMA Computer Algebra Program from LISP ecosystem. That is a system for the manipulation of symbolic and numerical expressions, including differentiation, integration and many other useful things. It will be  nice to have such a power in ClojureScript, is'nt it? I don't think that all those symbolic comutations can be simply programmed without eval.

-Ru

суббота, 13 февраля 2016 г., 18:25:46 UTC+3 пользователь ru написал:
Dear ClojureScript users and team!

Herwig Hochleitner

unread,
Feb 13, 2016, 12:14:55 PM2/13/16
to clo...@googlegroups.com
ru,

eval is there in clojurescript. It's just in a separate namespace. This is a good thing, because it leads to big space savings in the regular case.

ru

unread,
Feb 13, 2016, 12:50:37 PM2/13/16
to Clojure
That I understand. Only one more question. Can I unload ClojureScript Compiler after I done with "eval"? This scenario is suitable very well to my task.

-Ru

суббота, 13 февраля 2016 г., 18:25:46 UTC+3 пользователь ru написал:
Dear ClojureScript users and team!

James Reeves

unread,
Feb 13, 2016, 1:09:11 PM2/13/16
to clo...@googlegroups.com
On 13 February 2016 at 17:11, ru <sor...@oogis.ru> wrote:
First thing that comes to my mind is MAXIMA Computer Algebra Program from LISP ecosystem. That is a system for the manipulation of symbolic and numerical expressions, including differentiation, integration and many other useful things. It will be  nice to have such a power in ClojureScript, is'nt it?

Honestly, I think you'd usually want to use macros for tasks like that. There's a much higher incentive to use macros over eval in ClojureScript, as although there are disadvantages associated with macros, they also allow for a lot of precomputation. This is particularly important in a browser environment, where ClojureScript is most often used.

On 13 February 2016 at 17:50, ru <sor...@oogis.ru> wrote:
That I understand. Only one more question. Can I unload ClojureScript Compiler after I done with "eval"? This scenario is suitable very well to my task.

I don't believe you'd want to. The primary cost of including the compiler for the browser is the time taken to download and execute the javascript. I guess you could unbind the references and let it GC, but I don't think there'd be much point in doing that.

- James

ru

unread,
Feb 13, 2016, 1:58:47 PM2/13/16
to Clojure
I think macros can't be of much help in my task. I am working on project rete4frame (https://github.com/rururu/rete4frames) and now want to port it to ClojureScript. It is CLIPS-like expert system shell with simplified version of RETE algorithm. It has its own language with LISP syntax and it is a superset of Clojure/ClojureScript in a sence that it contains inside rule descriptions pieces of arbitrary Clojure/ClojureScript code. Work of system consists of two phases: Translation and Run. I use "eval" during Translation phase in Clojure to get pieces of code "executeble" on Run phase. So, I need solution how it can be done in ClojureScript.

-Ru

суббота, 13 февраля 2016 г., 18:25:46 UTC+3 пользователь ru написал:
Dear ClojureScript users and team!

David Nolen

unread,
Feb 13, 2016, 2:13:50 PM2/13/16
to clojure
If you need eval then you need to be OK with pulling in a lot of code and giving up Closure advanced optimizations and dead code elimination. Whatever small size savings an interpreter might offer, it would still suffer from this fundamental problem.

David

--

James Reeves

unread,
Feb 13, 2016, 2:18:33 PM2/13/16
to clo...@googlegroups.com
On 13 February 2016 at 18:58, ru <sor...@oogis.ru> wrote:
I think macros can't be of much help in my task. I am working on project rete4frame (https://github.com/rururu/rete4frames) and now want to port it to ClojureScript. It is CLIPS-like expert system shell with simplified version of RETE algorithm. It has its own language with LISP syntax and it is a superset of Clojure/ClojureScript in a sence that it contains inside rule descriptions pieces of arbitrary Clojure/ClojureScript code.

If you do have a use-case that absolutely requires eval and cannot be done in a different way, then cljs.js/eval is probably the thing you want.

- James

ru

unread,
Feb 13, 2016, 2:29:55 PM2/13/16
to Clojure
Many thanks for the explanations. I will be experimenting to deside where to go further.

-Ru

суббота, 13 февраля 2016 г., 18:25:46 UTC+3 пользователь ru написал:
Dear ClojureScript users and team!

Alan Moore

unread,
Feb 13, 2016, 8:41:47 PM2/13/16
to Clojure
Ru,

Take a look at the approach used by Clara (https://github.com/rbrush/clara-rules.) It works in both Clojure and ClojureScript. It translates the DSL using eval at macro-expansion time to generate the productions - see defsession.

Will take a look at rete4frames again when I get a chance.

Good luck!

Alan

ru

unread,
Feb 14, 2016, 5:06:36 AM2/14/16
to Clojure
Thank you Alan for very helpful information. I know about Clara but don't watch its progress attentively fore some time :(

Regards,
  Ru

суббота, 13 февраля 2016 г., 18:25:46 UTC+3 пользователь ru написал:
Dear ClojureScript users and team!

ru

unread,
Feb 14, 2016, 6:02:34 AM2/14/16
to Clojure
I took a look at the Clara's code. This is excerpt from the comment of "defsession" defmacro: "..Each source is eval'ed at compile time, in Clojure (not ClojureScript.)..".
So, this is a solution, but not clear ClojureScript solution :(

-Ru

суббота, 13 февраля 2016 г., 18:25:46 UTC+3 пользователь ru написал:
Dear ClojureScript users and team!
Reply all
Reply to author
Forward
0 new messages