On Tue, Apr 28, 2015 at 10:44 AM, Gary Verhaegen <gary.verhae...@gmail.com> wrote:
> On 28 April 2015 at 07:39, Atamert Ölçgen <mu...@muhuk.com> wrote: > > Perhaps you can write a function that builds a function somewhere and > then > > outputs a string containing JavaScript code that invokes it. > > > > (defn js [& body] > > (eval `(defn fn-name# [] ~@body)) > > (str "function() { your.ns." fn-name# "(); }")) > > If the goal is to send this code to a database to be evaluated there, > I do not think this would work, as the function is only defined within > Clojure. > You are right. Now that I've read OP more carefully; I think exploring your idea is really worth it, since it would allow the consumers of this library to write their transactions in ClojureScript instead of JavaScript. > > @OP: as you admit that this is a crazy need, here is a crazy solution: > use the ClojureScript compiler directly within your Clojure code. I'm > not familiar with it at all; after a quick glance at the Himera source > code, here is a "proof of concept": > > -- > > $ lein try org.clojure/clojurescript "0.0-3211" > nREPL server started on port 52299 on host 127.0.0.1 - nrepl:// > 127.0.0.1:52299 > REPL-y 0.3.5, nREPL 0.2.6 > Clojure 1.6.0 > Java HotSpot(TM) 64-Bit Server VM 1.8.0_25-b17 > Docs: (doc function-name-here) > (find-doc "part-of-name-here") > Source: (source function-name-here) > Javadoc: (javadoc java-object-or-class-here) > Exit: Control+D or (exit) or (quit) > Results: Stored in vars *1, *2, *3, an exception in *e > > user=> (require '[cljs.compiler :as comp]) > nil > user=> (require '[cljs.analyzer :as ana]) > nil > user=> (comp/emit-str (ana/analyze {:uses #{'cljs.core}} '(fn [] > (js/alert "hello")))) > "(function (){\nreturn alert(\"hello\");\n});\n" > user=> > > -- > > The first argument to analyze is the environment; you'll probably have > to dig a little deeper into the ClojureScript compiler to decide what > to pass there. This should allow you to create a macro that let you > write ClojureScript code directly: > > {:some-key :some-value, > :action (js-macro (fn [] > (js/console.log "pretty crappy transaction") > (js/console.log "another line")))} > > -- > 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. > -- Kind Regards, Atamert Ölçgen ◻◼◻ ◻◻◼ ◼◼◼ www.muhuk.com www.olcgen.com -- 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.