Fork me on GitHub
#clojurescript
<
2021-11-17
>
borkdude19:11:01

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

thheller08:11:27

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])

thheller08:11:16

a little different than regular CLJS but achieves the same result

borkdude08:11:13

ok, so you first try the lib as is, and then try with clojure replaced with cljs

thheller08:11:21

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

borkdude08:11:57

and then there is clojure.edn which is real but kind of delegates to cljs.reader

thheller08:11:02

well yeah but its just a regular ns

borkdude08:11:35

that's what I meant with real :)

Richard Bowen22:11:23

Hey, how does nesting an if in a for work?

p-himik22:11:42

What exactly do you mean? Can you give an example?

Richard Bowen22:11:35

(for [item indexed-data]
  (cond (= (first item) 0)
    (println "First item!"))
  (cond (= (last data) item)
    (println "Last item!"))
    (item))

Richard Bowen22:11:02

How do conditionals work within a for loop?

p-himik22:11:23

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.

isak22:11:53

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-542692c7c026201cdc326952

isak22:11:32

Also keep in mind that for yields a lazy sequence, so you may want doseq if you are doing this for side effects