clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
Sam Ritchie 2021-03-28T03:48:30.309900Z

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

Sam Ritchie 2021-03-28T03:59:13.310500Z

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

lilactown 2021-03-28T18:34:19.317300Z

seems like a bug

2021-03-28T05:04:51.310600Z

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.

2021-03-28T05:05:24.311100Z

Same thing happens for Clojure namespace names -> file names for require, and for Java class names generated from Clojure names.

alexmiller 2021-03-28T05:05:32.311500Z

We fixed something like this in Clojure back around 1.6

2021-03-28T07:35:49.312400Z

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?

raspasov 2021-03-28T08:07:00.312500Z

I believe this is specific to ClojureScript; as per the CLJS docs about *ns*:

Var bound to the current namespace. Only used for bootstrapping.

raspasov 2021-03-28T08:08:16.312700Z

raspasov 2021-03-28T08:09:14.312900Z

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.

raspasov 2021-03-28T08:09:52.313100Z

Note: it needs to be a .cljc file (and not .cljs)

thheller 2021-03-28T08:12:18.313300Z

yeah, *ns* is available in macros but otherwise not available in CLJS

2021-03-28T08:31:04.313500Z

Then how can one know which ns it is currently in ?

raspasov 2021-03-28T08:35:29.313700Z

@i you have to use a macro; the example above works.

thheller 2021-03-28T08:53:38.313900Z

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

raspasov 2021-03-28T08:57:31.314100Z

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

thheller 2021-03-28T08:58:22.314300Z

there is no such thing as being "in" an ns at runtime

raspasov 2021-03-28T08:58:53.314600Z

Yeah that’s why I put it in quotes 🙂

thheller 2021-03-28T09:00:00.314800Z

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 🙂

raspasov 2021-03-28T09:00:26.315Z

Interesting; so even in a macro not a good idea?

thheller 2021-03-28T09:04:34.315200Z

in macro it is fine. that is not runtime, that is compile time and running in CLJ

raspasov 2021-03-28T09:05:47.315400Z

Ah, got it. Cool.

raspasov 2021-03-28T09:14:58.315600Z

Found this weird trick on SO:

(apply str (drop-last 2 (str `_)))

thheller 2021-03-28T09:16:24.316200Z

(symbol (namespace ::foo))

1👌
zackteo 2021-03-28T10:34:52.316700Z

will do!

oliver 2021-03-28T14:10:49.317Z

Anyone got an idea how this could be configured?

lilactown 2021-03-28T18:34:19.317300Z

seems like a bug