Fork me on GitHub
#clojurescript
<
2022-05-26
>
pinkfrog08:05:24

Hi. It is said var is not reified in cljs. I wonder what var compiles to in js. If say,

(def a 3) 
compiles to
some_obj.a = 3
Then isn’t it something similar to a var? a still provides indirection, just like var itself.

p-himik08:05:45

But you have no access to that some_obj.a, unless you export it. After optimizations, it's just a mangled text. Also, I'd think that potentially GCC can even inline such things.

thheller09:05:49

var in clojure is a thing that holds a thing. think of it as an atom that can carry metadata as well as the thing in it.

thheller09:05:20

so no it is not similar in that regard. it is similar if you only care about the thing inside, not the thing holding it

pinkfrog13:05:42

For a cljs file

(ns app.main)

(def foo 42)

(defn -main
  []
  (prn "hello world"))
It transpiles to
// Compiled by ClojureScript 1.11.54 {:optimizations :none}
goog.provide('app.main');
goog.require('cljs.core');
app.main.foo = (42);
app.main._main = (function app$main$_main(){
return cljs.core.prn.call(null,"hello world");
});

//# sourceMappingURL=main.js.map
So the object app.main behaves quite similar to a namespace and app.main.foo also acts quite like a var, providing the indirection to a value. My question is, why doesn’t cljs map *ns* to some object like app.main, and also since app.main.foo is quite like a var , how come functionalities like intern is not supported in cljs? I’d like to make sure if it is technically infeasible to do that ? or just historically people don’t do it.

thheller17:05:40

it just isn't possible. look at the code again after :advanced optimizations and you'll understand

p-himik21:05:24

pinkfrog needs it only in the REPL though, so optimizations should be irrelevant there, right?

pinkfrog00:05:13

> it just isn’t possible. look at the code again after :advanced optimizations and you’ll understand Looking at the generated “advanced” code, it’s some mangled texted. Continuing the above example, my understanding is the changed things are only the names. app.main is mangled to some random xxxyy names, yet it is still an js object (functioning similar to a ns), and even the attribute foo is also mangled, it still provides indirection.

pinkfrog00:05:42

> pinkfrog needs it only in the REPL though, Yes. The relevant code are only run/triggered from a repl.

thheller06:05:31

sorry I must have missed the part where you explain what you are trying to do

thheller06:05:56

and no app.main is no longer still a JS object with properties. it'll be collapsed and just be something like Xc

eighttrigrams11:05:09

In a fresh - no tooling (i.e. following the official quickstart guide) - ClojureScript project, can I recompile and refresh the page somehow without leaving and restarting the REPL? I know I can interact via the REPL with the running environment, but I don't know how to make that the overall changes to a core.cls would then take effect without restart.

dnolen13:05:47

same as Clojure you can reload namespaces with (require 'some.ns :reload)

👍 1