This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-17
Channels
- # aleph (4)
- # announcements (2)
- # babashka (85)
- # beginners (136)
- # calva (72)
- # clj-commons (32)
- # clj-kondo (7)
- # cljs-dev (3)
- # clojure (117)
- # clojure-europe (38)
- # clojure-nl (3)
- # clojure-norway (1)
- # clojure-uk (4)
- # clojurescript (19)
- # conjure (38)
- # core-logic (2)
- # cursive (10)
- # datalevin (1)
- # datalog (1)
- # datomic (6)
- # events (2)
- # fulcro (16)
- # google-cloud (5)
- # graphql (10)
- # gratitude (3)
- # hugsql (3)
- # luminus (5)
- # membrane-term (12)
- # missionary (2)
- # nextjournal (5)
- # off-topic (3)
- # pedestal (2)
- # polylith (7)
- # portal (3)
- # re-frame (6)
- # reagent (26)
- # reclojure (8)
- # releases (3)
- # reveal (5)
- # shadow-cljs (14)
- # spacemacs (20)
- # sql (3)
- # tools-build (3)
- # web-security (9)
In ClojureScript: (require '[clojure.test :as t])
and then
`t/is
returns cljs.test/is
Where does the transformation of clojure.test
to cljs.test
happen? Is there a fixed built-in list or is there an automatic translation for anything starting with clojure.*
with a fallback to cljs.*
?
Similar for:
cljs.user=> `clojure.core/inc
cljs.core/inc
shadow-cljs handles this when resolving dependencies and then adding an alias to the ns, so basically it switches (require '[clojure.test :as t])
to (require '[cljs.test :as t])
yeah the whole behavior is a bit weird since there is an actual clojure.string
for example where replacing it to cljs.string
would be invalid
Hey, how does nesting an if in a for work?
(for [item indexed-data]
(cond (= (first item) 0)
(println "First item!"))
(cond (= (last data) item)
(println "Last item!"))
(item))
How do conditionals work within a for loop?
The code above is invalid because for
's body can have only one expression, whereas yours have two.
But conditionals works just as they do anywhere else. They're evaluated and the result is returned, becoming an element in the sequence that for
returns, even if it's nil
.
One exception if you use the :when
keyword:
(for [x [0 1 2 3 4 5]
:let [y (* x 3)]
:when (even? y)]
y)
=>
(0 6 12)
https://clojuredocs.org/clojure.core/for#example-542692c7c026201cdc326952Also keep in mind that for
yields a lazy sequence, so you may want doseq
if you are doing this for side effects
Okay. Thanks.