Re: Bizarre ClojureScript issue
Absolutely. -- 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: Bizarre ClojureScript issue
It's odd that it works fine in the first one but no the second. You'd think with that post button being so small that it'd be difficult to... yeah. -- 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: Bizarre ClojureScript issue
are you sure you don't have an extra space in there? (. createConnection net …) vs. (.createConnection net …) On Wed, Jul 27, 2011 at 5:38 PM, Anthony Grimes disciplera...@gmail.com wrote: Sorry for the terrible subject line. I couldn't think of an easy way to describe the problem in a single line. (def net (node/require net)) (defn portal [port host] (.createConnection net port host)) (defn -main [ args] ; Note that only one of these -main functions is in the file at any given time, of course. (.createConnection net 1337 localhost)) (defn -main [ args] (portal 1337 localhost)) (set! *main-cli-fn* -main) For some reason, the first -main above works fine but the second doesn't. When I use the second and try to run it, I get this: TypeError: Cannot read property 'net' of undefined Why would my 'portal' function not be able to see 'net', or is that even what this means? I'm unfamiliar with these JavaScriptish error messages. : I have no idea what is causing this. I reviewed the node example in the sample directory and I don't see what I'm missing. It's odd that it works fine in -- 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 -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? -- 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: Bizarre ClojureScript issue
Yep, just double checked. No extra spaces. -- 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: Bizarre ClojureScript issue
have you looked at the generated javascript? On Wed, Jul 27, 2011 at 5:44 PM, Anthony Grimes disciplera...@gmail.com wrote: Yep, just double checked. No extra spaces. -- 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 -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? -- 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: Bizarre ClojureScript issue
Yeah. To the extent that I can read Javascript, the calls look exactly the same and it looks fine. -- 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: Bizarre ClojureScript issue
On Wed, Jul 27, 2011 at 8:38 PM, Anthony Grimes disciplera...@gmail.com wrote: Sorry for the terrible subject line. I couldn't think of an easy way to describe the problem in a single line. (def net (node/require net)) (defn portal [port host] (.createConnection net port host)) (defn -main [ args] ; Note that only one of these -main functions is in the file at any given time, of course. (.createConnection net 1337 localhost)) (defn -main [ args] (portal 1337 localhost)) (set! *main-cli-fn* -main) For some reason, the first -main above works fine but the second doesn't. When I use the second and try to run it, I get this: TypeError: Cannot read property 'net' of undefined Why would my 'portal' function not be able to see 'net', Caveat: I'm by no means a ClojureScript expert. But maybe net is a private member of a class of which -main ends up a method, somewhat like how gen-class works in plain Clojure, and so -main can see it whereas portal, as a free-standing function, can't? -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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: Bizarre ClojureScript issue
That's actually what I thought at first, but the node example that ships with ClojureScript actually does the same thing (uses a node function outside of -main and then calls that function from -main) I did and it works fine. Here is the generated JavaScript for the failing -main and such: portal.core.net = cljs.nodejs.require.call(null, net); portal.core.portal = function portal(b, c) { return portal.core.net.createConnection(b, c) }; portal.core._main = function(a) { cljs.core.array_seq(Array.prototype.slice.call(arguments, 0), 0); return portal.core.portal.call(null, 1337, localhost) }; And here is the generated JS for the working -main: portal.core._main = function(a) { cljs.core.array_seq(Array.prototype.slice.call(arguments, 0), 0); return portal.core.net.createConnection(1337, localhost) }; -- 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: Bizarre ClojureScript issue
On Wed, Jul 27, 2011 at 9:05 PM, Anthony Grimes disciplera...@gmail.com wrote: That's actually what I thought at first, but the node example that ships with ClojureScript actually does the same thing (uses a node function outside of -main and then calls that function from -main) I did and it works fine. Here is the generated JavaScript for the failing -main and such: portal.core.net = cljs.nodejs.require.call(null, net); portal.core.portal = function portal(b, c) { return portal.core.net.createConnection(b, c) }; portal.core._main = function(a) { cljs.core.array_seq(Array.prototype.slice.call(arguments, 0), 0); return portal.core.portal.call(null, 1337, localhost) }; And here is the generated JS for the working -main: portal.core._main = function(a) { cljs.core.array_seq(Array.prototype.slice.call(arguments, 0), 0); return portal.core.net.createConnection(1337, localhost) }; The generated portal function seems to want two arguments (b, c) but it's called with (null, 1337, localhost). Should that be happening? Not that that should cause portal.core.net to not resolve. -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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: Bizarre ClojureScript issue
The first argument to Javascript's 'call' is a 'this' argument. All generated functions are called like this. -- 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: Bizarre ClojureScript issue
On Wed, Jul 27, 2011 at 9:21 PM, Anthony Grimes disciplera...@gmail.com wrote: The first argument to Javascript's 'call' is a 'this' argument. All generated functions are called like this. If portal.core.net is an instance rather than a class variable then a null this would explain it not resolving. Is _main called with (null, arguments) or with (some_portal.core_object, arguments)? -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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: Bizarre ClojureScript issue
It looks like main is called the same way. Like I said, my example is not much different than the one that comes with cljs. (ns nodels (:require [cljs.nodejs :as nodejs])) (def fs (nodejs/require fs)) (def path (nodejs/require path)) (defn file-seq [dir] (tree-seq (fn [f] (.isDirectory (.statSync fs f) ())) (fn [d] (map #(.join path d %) (.readdirSync fs d))) dir)) (defn -main [ paths] (dorun (map println (mapcat file-seq paths (set! *main-cli-fn* -main) The above example is the one I'm talking about and works fine. It's weird. -- 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: Bizarre ClojureScript issue
On Wed, Jul 27, 2011 at 9:30 PM, Anthony Grimes disciplera...@gmail.com wrote: It looks like main is called the same way. Like I said, my example is not much different than the one that comes with cljs. (ns nodels (:require [cljs.nodejs :as nodejs])) (def fs (nodejs/require fs)) (def path (nodejs/require path)) (defn file-seq [dir] (tree-seq (fn [f] (.isDirectory (.statSync fs f) ())) (fn [d] (map #(.join path d %) (.readdirSync fs d))) dir)) (defn -main [ paths] (dorun (map println (mapcat file-seq paths (set! *main-cli-fn* -main) The above example is the one I'm talking about and works fine. It's weird. I see some maybe-salient differences: 1. The working example has an ns form. Maybe being in the JS equivalent of the default package is causing problems? 2. The working example has nodejs/require instead of node/require in the defs. However, if you're using (ns something (:require [cljs.nodejs :as node])) and just didn't post it then neither of those can be related to the cause... -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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: Bizarre ClojureScript issue
Is it possible that the new function called portal is overwriting the namespace called portal? Could you try renaming the function called portal to something else? Like portal2? On Wed, Jul 27, 2011 at 6:05 PM, Anthony Grimes disciplera...@gmail.com wrote: That's actually what I thought at first, but the node example that ships with ClojureScript actually does the same thing (uses a node function outside of -main and then calls that function from -main) I did and it works fine. Here is the generated JavaScript for the failing -main and such: portal.core.net = cljs.nodejs.require.call(null, net); portal.core.portal = function portal(b, c) { return portal.core.net.createConnection(b, c) }; portal.core._main = function(a) { cljs.core.array_seq(Array.prototype.slice.call(arguments, 0), 0); return portal.core.portal.call(null, 1337, localhost) }; And here is the generated JS for the working -main: portal.core._main = function(a) { cljs.core.array_seq(Array.prototype.slice.call(arguments, 0), 0); return portal.core.net.createConnection(1337, localhost) }; -- 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 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: Bizarre ClojureScript issue
Hah! That was it! You, sir, are one clever fellow. Thank you very much. -- 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: Bizarre ClojureScript issue
On Wed, Jul 27, 2011 at 9:48 PM, Anthony Grimes disciplera...@gmail.com wrote: Hah! That was it! You, sir, are one clever fellow. Thank you very much. Damn. I didn't think of that. In normal Clojure, defn'ing x.y/x doesn't clobber the Java package named x with a function named x. But it looks like in JS packages and functions go into the same namespace, so the defn shadows portal later on and portal.net looks for a member net in the portal function object instead of the portal namespace. Another gotcha with ClojureScript vs. Clojure, where a function named portal.core/portal would work fine. The error message could clearly stand some improvement: it should clearly identify the object it was trying to find something in. Instead of TypeError: Cannot read property 'net' of undefined it should have said TypeError: Cannot read property 'net' of 'portal', which is an object of type 'function' or something. Then it would have been clear it was looking inside the function object instead of a namespace object for net. The fix for this may be quite simple: have the compiler generate code to pass the function object instead of null as the first parameter when it generates those .call calls. :P -- Protege: What is this seething mass of parentheses?! Master: Your father's Lisp REPL. This is the language of a true hacker. Not as clumsy or random as C++; a language for a more civilized age. -- 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