This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-26
Channels
- # aleph (1)
- # announcements (9)
- # aws (6)
- # babashka (18)
- # babashka-sci-dev (25)
- # beginners (79)
- # calva (30)
- # cider (34)
- # clj-kondo (25)
- # cljsrn (6)
- # clojure (26)
- # clojure-australia (1)
- # clojure-europe (6)
- # clojure-norway (1)
- # clojure-poland (6)
- # clojure-uk (3)
- # clojured (2)
- # clojurescript (14)
- # datomic (19)
- # events (1)
- # google-cloud (1)
- # gratitude (2)
- # helix (1)
- # hyperfiddle (2)
- # interceptors (1)
- # jobs (17)
- # joyride (96)
- # leiningen (5)
- # lsp (20)
- # minecraft (2)
- # nbb (5)
- # other-languages (1)
- # re-frame (34)
- # releases (2)
- # shadow-cljs (15)
- # spacemacs (1)
- # xtdb (19)
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.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.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.
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.
Thanks!