Fork me on GitHub

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.


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.


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.


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


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.require('cljs.core'); = (42);
app.main._main = (function app$main$_main(){
return,"hello world");

So the object app.main behaves quite similar to a namespace and 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 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.


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


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


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


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


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


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


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.


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

👍 1