Clojurescript question

307 views
Skip to first unread message

Paul Gearon

unread,
Nov 17, 2012, 2:36:57 PM11/17/12
to clo...@googlegroups.com
Looking at the Clojurescript page on Github I can't find the appropriate place to ask about potential bugs.... unless it's here. Can anyone help please? (David?)

Meanwhile, in case it's the correct place, I've tried the following as a simple test to run on Node.js:

---
(ns jpp.core)
(defn -main [& args]
  (.log js/console "Hello, World!\n"))
(set! *main-cli-fn* -main)
---

This works OK.

However, the following will not work (though variations on this have been seen to work):

---
(ns jpp.core)
(defn -main []
  (.log js/console "Hello, World!\n"))
(-main)
---

The output in this case is as follows:

Hello, World!


/Users/pag/src/test/clj/jpp/pp.js:72
ments supported on functions"))}var Vd,Wd=j;function Xd(a,b){var c=a.q;if(a.m)
                                                                    ^
TypeError: Cannot read property 'q' of null
    at Function.Xd [as b] (/Users/pag/src/test/clj/jpp/pp.js:72:280)
    at Object.<anonymous> (/Users/pag/src/test/clj/jpp/pp.js:157:244)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)


Interestingly, it's printed the correct output, but fails after. Also, do I mention in the same place that I get a different set of errors when I try to use the lein-cljsbuild plugin?

Regards,
Paul Gearon

Mimmo Cosenza

unread,
Nov 17, 2012, 2:43:10 PM11/17/12
to clo...@googlegroups.com
I just submitted the first one few hours ago:

here is the page where I found the link to jira



and here is the jira url


mimmo

--
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

David Nolen

unread,
Nov 17, 2012, 7:52:21 PM11/17/12
to clo...@googlegroups.com
What is the error under simple optimizations? Errors under advanced optimizations are not particularly informative :)

Thanks
--

Paul Gearon

unread,
Nov 18, 2012, 12:11:27 AM11/18/12
to clo...@googlegroups.com

On Saturday, 17 November 2012 19:52:39 UTC-5, David Nolen wrote:
What is the error under simple optimizations? Errors under advanced optimizations are not particularly informative :)

Good point, sorry.

Every minor change, is leading to significant differences, so I'm trying to strip it right back at the moment. Ideally I want to compile using Leiningen, but that's not consistent with the command line (I learned tonight that there is a difference in versions there, but that Leiningen should work).

Looking in some of the Clojurescript code I saw the comment that the call to cljs.core/*main-cli-fn* always happens for node.js, so I've gone back to using it. Now my file looks like:

(ns cljshello.core)
(defn -main [& argv]
    (println "Hello, World!\n"))
(set! *main-cli-fn* -main)

I'm using a project of:

(defproject cljshello "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :license {:name "Eclipse Public License"
  :dependencies [[org.clojure/clojure "1.5.0-alpha7"]
                 [org.clojure/clojurescript "0.0-1535"]]
  :plugins [[lein-cljsbuild "0.2.9"]]
  :hooks [leiningen.cljsbuild]
                        
  :cljsbuild {
    :builds [{
      :source-path "src"
      :compiler { :output-to "pp.js"
                  :target :nodejs
                  :pretty-print true }}]})

Using "lein compile" on this I get a stack trace starting with:

Reloading Clojure file "/cljshello/core.clj" failed.
clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unable to resolve symbol: *main-cli-fn* in this context, compiling:(cljshello/core.clj:7:1)

..... though, in the process of writing this email I tried changing the :source-path to the specific file I am compiling and the compile finished without warning. Am I correct in guessing that I'm supposed to describe a build for each file?

All the same, whether I get a warning or not I still get a pp.js file. Running this file under either conditions (error in compilation or not) gives me:

/Users/pag/src/test/clj/cljshello/pp.js:493
goog.string.Unicode = {NBSP:"\u00a0"};
                    ^
TypeError: Cannot set property 'Unicode' of undefined
    at Object.<anonymous> (/Users/pag/src/test/clj/cljshello/pp.js:493:21)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)


However, the same file is now compiling with the cli compiler, so I'll try to work with it for the moment.

Paul

Paul Gearon

unread,
Nov 18, 2012, 12:28:27 AM11/18/12
to clo...@googlegroups.com
Since HelloWorld worked for me, I tried to output the command line arguments as a string. Consequently, the program now looks like:

(ns cljshello.core
  (:require [cljs.nodejs :as nj]))

(defn -main [& argv]
    (println (str "Hello, World!" (.-argv nj/process) "\n")))

(set! *main-cli-fn* -main)

Again, I am able to compile with either leiningen or the command line with the same result. This time, I'm getting:

/Users/pag/src/test/clj/cljshello/pp.js:350
cljs.core.apply=function(){var a=null,b=function(a,b){var c=a.cljs$lang$maxFix
                                                             ^
TypeError: Cannot read property 'cljs$lang$maxFixedArity' of null
    at cljs.core.apply.b (/Users/pag/src/test/clj/cljshello/pp.js:350:62)
    at cljs.core.apply.a (/Users/pag/src/test/clj/cljshello/pp.js:354:118)
    at Object.<anonymous> (/Users/pag/src/test/clj/cljshello/pp.js:926:421)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

Since I should already have argv being passed in, I changed the expression to use it directly, instead of using (.-argv nj/process), however, this changed nothing.

Happy to try any suggestions you may have for me.

Paul

David Nolen

unread,
Nov 18, 2012, 4:10:25 PM11/18/12
to clojure
There's still not enough context. What is the code at line 926 in pp.js that is causing the issue? It's best to compile with your code w/ pretty printing of the JS source enabled to ease w/ debugging, this can be done w/ setting :pretty-print true.

David


--
Reply all
Reply to author
Forward
0 new messages