1
votes

i faced a super weird issue today

(let [t :cognitive
      tab (name t)
      tab-name (string/join "" (take 3 (string/split tab #"")))]
  (println "@@@" t tab tab-name))

returns

@@@ :cognitive cognitive cog

in clojure, but

@@@ :cognitive cognitive co

in clojurescript (rendered using reagent). notice the missing g in the cljs version

i have tried doall before-and-after the (take 3 ... expression, but to no avail

BTW, i'm using

[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.170"]

for my cljs project, and

[org.clojure/clojure "1.8.0"]

for the clj project

1
I'm guessing there's some other reason you're using string/split on the string, but just thought I'd mention that strings are coerced to sequences. So you could just use (take 3 tab) in your example. - Nathan Davis
hey @NathanDavis, i didn't think of that. thanks for pointing it out :) - Pradnyesh Sawant

1 Answers

2
votes

In cljs:

(string/split (name :cognitive) #"")

gives you:

["" "c" "o" "g" "n" "i" "t" "i" "v" "e"]

So your (take 3 ... is taking "", "c", and "o".

As to why--it is possible that the underlying String.split java method called by clojure and clojurescript is behaving differently between versions. [edited]