Converting clojure code to clojurescript

2012-04-19 Thread Mark Engelberg
I'm trying to get some Clojure code to compile to javascript. So I've got a clojurescript repl up and running, and I was hoping it would be a straightforward iterative process of: Compile code. Test code. Get detailed bug (or at least a line number) if I used a feature not available in clojurescri

Re: Converting clojure code to clojurescript

2012-04-19 Thread Dave Sann
clojurescript is still pretty young. Error reporting is not where I expect most people would like to see it. This is a problem for all languages complied to js at the moment. That said - you can get used to the situation pretty quickly, with a little patience and the occasional challenge. If y

Re: Converting clojure code to clojurescript

2012-04-19 Thread Dave Sann
Additionally, if you are using the repl to experiment, you may benefit from defining and testing each bit as you go. On Thursday, 19 April 2012 21:59:03 UTC+10, Dave Sann wrote: > > clojurescript is still pretty young. Error reporting is not where I expect > most people would like to see it. Thi

Re: Converting clojure code to clojurescript

2012-04-19 Thread Mark Engelberg
On Thu, Apr 19, 2012 at 4:59 AM, Dave Sann wrote: > If I have errors, I use the stacktrace which you can access easily in > chrome for example to get my bearing and figure out what is going on. > Can you elaborate on this? Right now, I'm using a rhino repl as per the getting started instruction

Re: Converting clojure code to clojurescript

2012-04-19 Thread Dave Sann
If you are running in a browser - the console log will show a stacktrace that you can use. As you are using Rhino, sorry I don't use this. Others may be able to help. (I think that *e and .printStackTrace are clojure repl and jvm interop respectively - not available in cljs) If you are porting

Re: Converting clojure code to clojurescript

2012-04-19 Thread Mark Engelberg
On Thu, Apr 19, 2012 at 10:01 AM, Dave Sann wrote: > The error that you showed originally does not look like a compile error - > but an execution error. I may be wrong. > Agreed. The error happens only when I execute the code, not when I compile it. Since the code works fine in Clojure, my bes

Re: Converting clojure code to clojurescript

2012-04-19 Thread David Nolen
How are you compiling the code? David On Thu, Apr 19, 2012 at 5:55 AM, Mark Engelberg wrote: > I'm trying to get some Clojure code to compile to javascript. > > So I've got a clojurescript repl up and running, and I was hoping it would > be a straightforward iterative process of: > Compile code.

Re: Converting clojure code to clojurescript

2012-04-19 Thread Mark Engelberg
On Thu, Apr 19, 2012 at 10:56 AM, David Nolen wrote: > How are you compiling the code? > > David > > In the REPL, using (ns test (:require [namespace-of-file-I-want-to-compile :as s])) and then invoking the functions using (s/function item). -- You received this message because you are subscribe

Re: Converting clojure code to clojurescript

2012-04-19 Thread David Nolen
How are you starting the REPL? What version of ClojureScript? Are you using lein-cljsbuild? On Thu, Apr 19, 2012 at 2:09 PM, Mark Engelberg wrote: > On Thu, Apr 19, 2012 at 10:56 AM, David Nolen wrote: > >> How are you compiling the code? >> >> David >> >> > In the REPL, using (ns test (:require

Re: Converting clojure code to clojurescript

2012-04-19 Thread Mark Engelberg
lein-cljsbuild's trampoline tasks for starting REPLs are not working for me (I reported this in another thread). Seems to be a problem with lein's batch file for Windows not properly handling spaces in directories that relate to plugins. So I do lein repl (I've configured the project file with ad

Re: Converting clojure code to clojurescript

2012-04-19 Thread David Nolen
Then you need construct your REPL with: (repl/repl env :warn-on-undeclared true) David On Thu, Apr 19, 2012 at 2:27 PM, Mark Engelberg wrote: > lein-cljsbuild's trampoline tasks for starting REPLs are not working for > me (I reported this in another thread). Seems to be a problem with lein's >

Re: Converting clojure code to clojurescript

2012-04-19 Thread Mark Engelberg
OK, this was very helpful advice. Using these warnings I was able to identify several problems: Clojurescript didn't like my use of defstruct Clojurescript didn't like my throwing of a RuntimeException Clojurescript doesn't understand the format function (is there a substitute in Clojurescript-la

Re: Converting clojure code to clojurescript

2012-04-19 Thread Dave Sann
yes. because this would be interpreted as a function/var that was expected to be defined in the current namespace - you will see this in generated code. my.namespace.function_I_thought_was_in_core David's :warn-on-undefined should pick this up for code compiled via the repl. -- You received

Re: Converting clojure code to clojurescript

2012-04-19 Thread Mark Engelberg
I've found that by completely exiting and restarting the REPL, it is working now. Woo hoo! Way, way, way slower though. 16 seconds to produce an answer that takes 6 milliseconds in Java. I have a suspicion that part of the time difference may have something to do with Clojurescript's treatment

Re: Converting clojure code to clojurescript

2012-04-19 Thread Evan Mezeske
Is the 16 seconds figure from running your code in Rhino? From what I've heard, the V8 engine is much, much faster (like, order(s) of magnitude) than Rhino. I'm not really sure what the best way to interactively run code on V8 is. You could compile with node.js as the platform, and I think Da

Re: Converting clojure code to clojurescript

2012-04-19 Thread Kevin Lynagh
Mark, There's a format-like function in the Closure library. Add to your namespace (:require [goog.string :as gstring] [goog.string.format :as gformat]) and call it like (gstring/format "%02.0f" (inc 8)) ;;or whatever. On Apr 19, 4:46 pm, Evan Mezeske wrote: > Is the 16 seconds fi

Re: Converting clojure code to clojurescript

2012-04-19 Thread Mark Engelberg
On Thu, Apr 19, 2012 at 4:46 PM, Evan Mezeske wrote: > Is the 16 seconds figure from running your code in Rhino? > Yes, Rhino. I'm also not doing any optimizations, although my understanding is that advanced optimizations is more about pruning code and reducing file size than reducing execution

Re: Converting clojure code to clojurescript

2012-04-19 Thread David Nolen
Rhino is slow. If you want to see performance anywhere near the JVM you to have to use a modern JavaScript engine - JavaScriptCore, SpiderMonkey, or Google V8. David On Thu, Apr 19, 2012 at 7:31 PM, Mark Engelberg wrote: > I've found that by completely exiting and restarting the REPL, it is > wo

Re: Converting clojure code to clojurescript

2012-04-19 Thread David Nolen
On Thu, Apr 19, 2012 at 8:43 PM, Mark Engelberg wrote: > On Thu, Apr 19, 2012 at 4:46 PM, Evan Mezeske wrote: > >> Is the 16 seconds figure from running your code in Rhino? >> > > Yes, Rhino. I'm also not doing any optimizations, although my > understanding is that advanced optimizations is more

Re: Converting clojure code to clojurescript

2012-04-19 Thread Mark Engelberg
OK, I ran the same test directly in the browser with optimizations. I wasn't doing it in a REPL, so I couldn't use the time function, but Firefox appeared to take about 2 seconds, and Chrome was definitely under a second. So yes, there does seem to be a world of difference from Rhino. I'm still

Re: Converting clojure code to clojurescript

2012-04-19 Thread Dave Sann
(binding [*print-fn* #(.log js/console)] (time ...)) works in the browser On Friday, 20 April 2012 11:25:31 UTC+10, puzzler wrote: > > OK, I ran the same test directly in the browser with optimizations. I > wasn't doing it in a REPL, so I couldn't use the time function, but Firefox > appeared

Re: Converting clojure code to clojurescript

2012-04-19 Thread David Nolen
On Thu, Apr 19, 2012 at 9:25 PM, Mark Engelberg wrote: > OK, I ran the same test directly in the browser with optimizations. I > wasn't doing it in a REPL, so I couldn't use the time function, but Firefox > appeared to take about 2 seconds, and Chrome was definitely under a > second. So yes, the