Fork me on GitHub
Luis C. Arbildo03:03:07

Hi How can I know when use :as or :default in require in clojurescript?


@UUGUA0MGQ I haven't seen :default mentioned in relation to require except with shadow-cljs, so you might check over in #shadow-cljs

Johannes Lötzsch13:03:46

(:require ["module-name" :default defaultExport]) is the same as ES6 import defaultExport from "module-name"; You find it at


what's a nice way to convert a sequence to a map? Suppose I have a seq (1 2 3 4) and I want to return a map of transforming each value {1 (tx 1) 2 (tx 2) 3 (tx 3) 4 (tx 4) }


I can think of a few ways passing through intermediate values, like building lists like ([1 (tx 1)] [2 (tx 2)] ...) and then converting the list to a hash-map, but it feels wasteful


I could use transducers, but I'm sure I'm missing a simple way


Something like: (->> your-seq (map #(vector % (tx %))) (into {})) . Trying to do this on phone so might be a bit shonky.


So similar to your first suggestion.


No neater way springs to mind.


You could use a reduce but I'm not sure it'd be any more readable.


(let [c '(1 2 3)] (zipmap c (map #(* % % %) c)))


oh internally it is implemented with assoc and loop/recur


I thought it was gonna be something more fancy 😛


Ah yes, I forgot zipmap. That's what I get for trying to code when I've just woken up. 😀

😁 1

How about (into {} (map (juxt identity f) '(1 2 3 4)))? f is your transformation.


I think I like (zipmap your-seq (map tx your-seq)) for this.


Like you had above

Phil Hunt13:03:58

Hi. I’ve played a bit with Clojure and know some Common Lisp. Does anyone have a view on whether the ClojureScript debugging experience is notably better than those nasty Java stacktraces you get in Clojure.?

Johannes Lötzsch13:03:53

Writing pure functions and directly evaluating them from Repl (or Editor) can provide a workflow making debugging in most cases simple. Usually it's not needed, but one can use the JS-Debugger of the Browsers Dev-Console. When logging debug-data, I recommend using the dev-tools-plugin in combination with js/console.log over prn, this allows to introspect nested datastructures very easily. If you like Javascript stacktrackes is your choice, but one can learn to read them and Chromium allows to click on line-numbers where the error occured and you see a marker directly in your cljs code — I think that's quite convenient

Phil Hunt13:03:59

Thanks for the quick answer. That sounds like it might be OK. I think I’m a bit spoiled from hacking around in CL with Slime/Emacs, but actually getting paid means dealing with JS and maybe Java codebases :)

Phil Hunt13:03:20

I’m thinking IntelliJ / Cursive might work better in a mixed environment, but I’m sort of liking Emacs now I’ve got the basics down.\

Phil Hunt15:03:33

Hmm well, I had a bit of a play with cljs ... tried boot and deps, tooling feels very JS (ie in a state of flux)

Baris Aydek16:03:04

Hi. I want to write specs for my map type. In the map I have two types ::a and ::b

{ ::type ::a, ::key1 1, ::key2 2 }
for type ::a I want ::key1 and ::key2 to be required. And for the type ::b
{ ::type ::b, ::key1 2, ::key3 3}
I want ::key2 and ::key3 to be required. I know i can write spec as a simple predicate function, but then I lose ability to use macros like s/keys. What I came so far:
(s/def ::mytake
  (fn [m] (let [type (::type m)] 
                 (= type ::a) 
                 (every? #(contains? m %) [::key1 ::key2]))
                 (= type ::b)
                 (every? #(contains? m %) [::key1 ::key3])))))) 
And when I test with
(s/valid? ::mytake {::type ::a, ::key1 1, ::key2 2})
(s/valid? ::mytake {::type ::b, ::key1 1, ::key3 3})
It works. But is there any better way?

Sam Heaton21:03:29

Hey folks. Scratching my head trying to get this function to work.

(defn table-strings->numbers [maps]
  (map (fn [x] update x :value (js/parseInt "25")) maps))
maps is a PersistentVector that contains PersistentHashMaps. I want to ultimately replace all of a specific value in each hashmap with the integer equivalent. The use case is sorting data that came over JSON and sorting the string representations of different numbers of digits does not work so well. However I can't get to first base - even just using (js/parseInt "25") as a placeholder to test the function but I am just getting back nil for the whole thing. Same whether I use update or assoc. Any clues?


You want to call update, right? I believe you are looking for the following

(defn table-strings->numbers [maps]
  (map (fn [x] (update x :value (js/parseInt "25"))) maps))
Simply missing some parens.

👍 1

Or use the syntax sugar for anonymous functions

(defn table-strings->numbers [maps]
  (map #(update % :value (js/parseInt "25")) maps))

👍 1
Sam Heaton21:03:58

I sent a reply but it’s disappeared. I can see here that I didn’t call update as a function and missed the parens. Thank you!

Sam Heaton21:03:39

This is ClojureScript btw


@include (following on from #clojure ) What editors are you most used to already?


@seancorfield so during the day I am more a vim guy but I can work with spacemacs with evilmode on


OK, cool. So the Emacs portion of Brave & True isn't too much of an obstacle for you 🙂 and there is good support for Clojure in vim I believe (although I'm not a vim guy so I'd point you to #vim for assistance there! 🙂 )


anyways I found intelij+ cursive also a good experience for noobs.


Yup, I hear that a lot. I'm an Atom/Chlorine person these days (after years of Emacs).


humm I thought Atom was slow.


does Atom/Chlorine has something like parinfer?


Sure. I have both parinfer and paredit installed in Atom.


Atom is "slower" than Emacs but I find it fast enough... certainly it's usable for our 90,000 lines of Clojure at work 🙂