This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-27
Channels
- # bangalore-clj (1)
- # beginners (27)
- # boot (16)
- # cider (14)
- # cljs-dev (94)
- # cljsrn (8)
- # clojure (229)
- # clojure-dev (5)
- # clojure-dusseldorf (6)
- # clojure-italy (8)
- # clojure-norway (8)
- # clojure-russia (22)
- # clojure-sanfrancisco (2)
- # clojure-spec (48)
- # clojure-uk (44)
- # clojurescript (47)
- # core-async (87)
- # cursive (43)
- # datascript (22)
- # datomic (20)
- # defnpodcast (5)
- # emacs (6)
- # hoplon (4)
- # jobs-rus (4)
- # keechma (2)
- # klipse (8)
- # leiningen (2)
- # luminus (2)
- # lumo (14)
- # om (38)
- # onyx (4)
- # overtone (3)
- # pedestal (41)
- # planck (72)
- # powderkeg (42)
- # proton (46)
- # protorepl (9)
- # reagent (9)
- # ring (47)
- # ring-swagger (5)
- # rum (7)
- # sql (22)
- # unrepl (1)
- # untangled (24)
- # vim (19)
- # yada (5)
Why doesn't this work?
$ cat lumo-test.cljs
(clojure.string/split "one\ntwo\nthree" #"\n")
$ lumo lumo-test.cljs
WARNING: No such namespace: clojure.string, could not locate clojure/string.cljs, clojure/string.cljc, or Closure namespace "" at line 1
And this does:
$ lumo
cljs.user=> (clojure.string/split "one\ntwo\nthree" #"\n")
["one" "two" "three"]
Adding a (require '[clojure.string :refer [split]])
makes everything fine for the lumo lumo-test.cljs
, but it's not needed at the repl. Why is that?@whitecoop rule of thumb is you should always require the stuff that you’re using
it happens to work at the REPL because the REPL namespace probably requires clojure.string
@anmonteiro ah. hadn't thought of that possibility. that makes sense.
you need to require the stuff you use so that the CLJS compiler can figure out the dependency tree
I've mostly thought of require
as primarily a convenience to not have to write our the full name (`clojure.string/split` vs split
, etc.)
but, now that I'm thinking about it, I suppose (require '[some.lib])
is about building the dependency tree and using :refer
, :as
, and such inside of the require
are the convenience part of the require
.
@whitecoop yeah, requires
really need to be explicit
to be clear, this is a Google Closure limitation
we can’t have dynamic requires in ClojureScript like we can in Clojure
but even in Clojure you need to require
stuff that you’re gonna use at some point
@anmonteiro ok. I was wondering about the CLJ vs CLJS part of this. so is needing to be explicit because of Google Closure is the case even without dead code elimination? obviously, we'd want to write with that in mind, but thus far, running stuff with lumo some.cljs
isn't using dead-code elimination, right?
@whitecoop yeah, this is not about dead code elimination
it’s about generating deps.js
, which Closure needs to know which namespaces to load