Hey all - curious if this is a bug, or behavior, that anyone here has encountered before?
(map (fn [e_i e-i] [e_i e-i])
[1 2 3] [4 5 6])
;;=> ([4 4] [5 5] [6 6])
it’s exactly what would happen if I had used the same arg name - I had forgotten that, of course, dashes get mapped to underscores
seems like a bug
Definitely ClojureScript-specific behavior, but makes sense if all of these local names must become mapped to legal JavaScript names. I suppose there are techniques that could generate guaranteed-unique names, but they would have to change some names, which for non-local names would make cljs/js interop more tricky, I would guess.
Same thing happens for Clojure namespace names -> file names for require
, and for Java class names generated from Clojure names.
We fixed something like this in Clojure back around 1.6
I started an rn app (written in cljs) and uses shadow repl to connect to it. When typing (prn ns), it gives nil. Why nil instead of some namespace?
I believe this is specific to ClojureScript; as per the CLJS docs about *ns*
:
Var bound to the current namespace. Only used for bootstrapping.
Try creating a scratch.cljc file like this; and then load it in another namespace; if you call (shared.scratch/macro-1) from that namespace, you should get the desired result.
Note: it needs to be a .cljc file (and not .cljs)
yeah, *ns*
is available in macros but otherwise not available in CLJS
Then how can one know which ns it is currently in ?
@i you have to use a macro; the example above works.
in the REPL the prompt prints it. in Cursive it is shown at the bottom right in the REPL input window. otherwise a quick trick is just evaling ::foo
, that'll give you :cljs.user/foo
or so
I meant you need to use a macro if you want to figure out which ns you’re “in” at runtime; otherwise during development, depends on the editor, yeah
there is no such thing as being "in" an ns at runtime
Yeah that’s why I put it in quotes 🙂
FWIW *ns*
is a binding which are problematic in CLJS due to the async nature. It is also normally a clojure.lang.Namespace
instance which CLJS doesn't have. so it is better to just not have it or rely on it 🙂
Interesting; so even in a macro not a good idea?
in macro it is fine. that is not runtime, that is compile time and running in CLJ
Ah, got it. Cool.
Found this weird trick on SO:
(apply str (drop-last 2 (str `_)))
(symbol (namespace ::foo))