Fork me on GitHub

try adding this line to your .emacs (setq cider-repl-use-pretty-printing t)

Imdad Ahmed10:11:57

This seems to only work with (setq cider-show-error-buffer 'only-in-repl) for errors


Is there a way to remove the namespace prefix from all the keys in a map? I’d like to json-stringify a map and send it over the wire w/o the ns


@titanroark If you just call name on those keys, you'll get strings without the namespace prefix.


There are a few walk-related functions in the Clojure library that can make that easier if it's a nested map. Or just use org.clojure/data.json (or Cheshire or jsonista) to turn it into actual JSON, which should all lose the namespace prefix, or can be configured to do so.


Ah.. I was using cheshire. Maybe I missed a config


I’m actually using your jdbc-next library. I saw up above someone ask a similar question and a response that toggled the namespaces on or off, but I was looking for something more general, thus this question.


When I did (name (:table/uuid_field) map) it threw an error saying a uuid type can’t be converted to a name

orpheus02:11:09 worked nicely though, thank you


(name (:table/uuid_field) map) -- that first tries to "call" the keyword :table/uuid_field with no arguments, hence the error: (:table/uuid_field) is a function call. (reduce-kv (fn [m k v] (assoc m (name k) v)) {} the-map) would apply name to each key in the-map. In Clojure 1.11 (Alpha 2), you could just say (update-keys the-map name)


data.json is a nice library because it's "fast enough" for nearly all uses and has absolutely no dependencies. Both Cheshire and jsonista bring in Jackson libraries (Java JSON stuff) that are notorious for causing conflicts with other libraries that also do JSON using (a different version) of Jackson.


Ah yes, I typed the function call out wrong in slack. And that update-keys fn sounds really nice. Thanks for the reduce-kv tip, the data.json library did the trick well for me, so I won’t need to manually map. And good to know about the library differences, Cheshire starts off with saying its faster so I just went with that


Yeah, it used to be. data.json has had some major speedups lately. It's not always the fastest - jsonista usually is - but it is certainly fast enough and we switched from Cheshire to data.json at work for all our production usage recently (to avoid Jackson). I blogged about at

🖤 1

dev=> (require '[ :as json])
dev=> (json/write-str {:foo/bar 1 :bar/quux "two"})
with the Contrib lib.

🙌 1

Hi I have the following reitit endpoint in my server:

     {:put {:summary ""
            :parameters {:role string?}
            :responses {200 {:body map?}
                        500 {:body string?}}
            :handler foo}}]
And I make the request using http-xhrio in reframe like so:
{:http-xhrio {:method          :put
                            :uri             (str "/organizations/" (get user "organization-id") "/users/" (get user "id"))
                            :params          {:role role}
                            :format          (ajax/json-request-format)
                            :response-format (ajax/json-response-format {:keywords true?})
                            :on-success      [:block-editing/handle-success]
                            :on-failure      [:block-editing/handle-error]}
But I get the following error:
xhrio.js:645 PUT  404 (Not Found)
Any ideas why?


1. do you have any prefix in the routes, e.g. ["/api" …]? 2. does foo return non-nil?


@U055NJ5CC I had forgotten “/api” but it still gives the same error:

PUT  400 (Bad Request)


no actually it gives bad request instead of not found


It may be worth while to put onto github or summat an example that fails, a fully working example


You can, for example, use my one as a basis.


(also, I think this may be better served in the #reitit channel?)


dump user and make sure organization-id and id are not nil


In core.async is there an opposite to "onto-chan" that returns a collection of the items in a channel? Is there a better alternative?


(a/<!! (a/reduce conj [] <tickets))
doing this now


I am writing out some data into an edn file I can see in the file its tagged like this :created #time/instant "2021-10-23T19:25:46.574852Z", how ever when I read it back in using slurp and read-string I get this :created (. java.time.Instant parse "2021-10-21T11:54:31.831771Z") this is causing my code to fail when I call things like tick/year I get an IExtraction error I would have expected the read edn to match the initial tag of #time/instant so bit baffled as to whats happening, any one able to point me in the right direction ?


never mind combination of things using the wrong read-string, and then needing to add my own reader for the tag

🦆 1
Nikhil Warke12:11:16

How do you pass arguments in double dot notation ((.. fs -promises readFile) "db.edn") or (.. fs -promises readFile "db.edn") P.S. - doesn't work with either of them This worked - (.readFile (.-promises fs) "db.edn")

Colin P. Hill13:11:26

it works just like ->, if you're familiar with that macro

Colin P. Hill13:11:20

The .. equivalent of the solution you found is

(.. fs
  (readFile "db.edn"))


(get-in m  [:a :b])
  (-> m :a :b)
which is better?

Ben Sless16:11:15

Performance, the latter, the rest is a matter of philosophy and taste


imho, a matter of preference, although with the get-in variant, you can have a default value if not found.

Alex Miller (Clojure team)17:11:03

you could have that with -> too, if "not found" is at a specific loc (-> m :a (:b :whoops)) :)


Did not know that 🙂 Thank you!


I've seen get-in used more often, but I think it's very preference/context dependant.


(I use both variants)


i’ve seen a good argument (i think from zach tellman) that you should always prefer to use the functions that most concretely represent the type. I need to go look it up. But i thought it was a useful guideline


get-in is more dynamic, e.g. the list of keys does not need to be a compile time constant


get-in also works for other kinds of keys


-> is likely going to be faster (constant fixed set of keys, for certain things keyword look up calls turn into field accesses), but maybe not by enough to care about, -> allows for more complicated processes because you can stick random functions in there

Alex Miller (Clojure team)17:11:44

-> is I think definitely faster right now (but that may not always be the case in the future)


that is surprising to me. i would have guessed get-in would be faster, kinda specialized to key value lookup


I mean, -> expands into a fixed set of function calls, get-in is a loop over the contents of a vector


by fixed I mean statically known at compile time

Alex Miller (Clojure team)17:11:06

user=> (dotimes [_ 10] (time (dotimes [_ 100000] (-> m :a :b))))
"Elapsed time: 5.769764 msecs"
"Elapsed time: 2.083059 msecs"
"Elapsed time: 2.065704 msecs"
"Elapsed time: 2.026249 msecs"
"Elapsed time: 1.989106 msecs"
"Elapsed time: 1.969671 msecs"
"Elapsed time: 1.446167 msecs"
"Elapsed time: 1.416666 msecs"
"Elapsed time: 1.408738 msecs"
"Elapsed time: 1.409222 msecs"
user=> (dotimes [_ 10] (time (dotimes [_ 100000] (get-in m [:a :b]))))
"Elapsed time: 21.282209 msecs"
"Elapsed time: 15.645264 msecs"
"Elapsed time: 13.058268 msecs"
"Elapsed time: 12.87428 msecs"
"Elapsed time: 7.01354 msecs"
"Elapsed time: 6.806815 msecs"
"Elapsed time: 6.66232 msecs"
"Elapsed time: 6.803173 msecs"
"Elapsed time: 18.48002 msecs"
"Elapsed time: 5.500962 msecs"

👍 2

good points. makes sense

Alex Miller (Clojure team)17:11:03

in opposition to the argument above, I think there is actually an argument to rely on as few assumptions about type as possible


that’s a really good point. I wish i could find where he made that argument so I could see the reasons and if he qualified it in any way


page 52 of elements of clojure


"use the narrowest possible data accessor"


the argument seems to be about communicating intent


yes it is guides for keeping the shape of data in the readers head as i remembered it. addressed by other means as well but still a decent idea to me


the counter argument is write the code as generically as possible so you have to care about the exact shape as little as possible

Alex Miller (Clojure team)17:11:33

there are plenty of times in Clojure where you can change the implementation between a map or a function, or between a vector or a list or a seq or even a set, without changing the caller. that's an amazing option to have.

👍 2

Damn, you beat me to it

Alex Miller (Clojure team)17:11:11

lookup is more generic than maps


lambda the ultimate

Alex Miller (Clojure team)17:11:01

but as I said, get-in could be, and should be, faster than it is so don't carry this performance comparison as absolute

Alex Miller (Clojure team)17:11:19

I use both -> and get-in in these cases and choose primarily on which one is easier to understand in the context of the code

catjam 1
Alex Miller (Clojure team)17:11:23

the perf argument is weak, unless you're in a very hot path here (like the page router of your web app)

Alex Miller (Clojure team)17:11:04

and even in that case, hotspot in a new jvm might make the above a wash

Alex Miller (Clojure team)17:11:05

in fact, that was java 8 above, here's java 17

user=> (dotimes [_ 10] (time (dotimes [_ 100000] (-> m :a :b))))
"Elapsed time: 11.085806 msecs"
"Elapsed time: 5.569733 msecs"
"Elapsed time: 5.167711 msecs"
"Elapsed time: 5.269218 msecs"
"Elapsed time: 5.093628 msecs"
"Elapsed time: 5.052448 msecs"
"Elapsed time: 5.143588 msecs"
"Elapsed time: 2.802478 msecs"
"Elapsed time: 1.395313 msecs"
"Elapsed time: 1.411534 msecs"
user=> (dotimes [_ 10] (time (dotimes [_ 100000] (get-in m [:a :b]))))
"Elapsed time: 21.824148 msecs"
"Elapsed time: 17.589059 msecs"
"Elapsed time: 13.940786 msecs"
"Elapsed time: 13.9655 msecs"
"Elapsed time: 3.989803 msecs"
"Elapsed time: 4.947388 msecs"
"Elapsed time: 4.247937 msecs"
"Elapsed time: 3.350112 msecs"
"Elapsed time: 4.805961 msecs"
"Elapsed time: 6.8933 msecs"

😮 1

(defn has-keys? [m keys]
  (apply = (map count [keys (select-keys m keys)])))
is this a good solution to check if a map have contains all of some given keys?


use every and contains?


ah I was missing every? thanks


that has-keys? is terrible


even something using reduce and contains? would be preferable


is there something like apply or [coll-of-key


I figured out this solves has-keys? if I'm not mistaken. Well I guess it doesn't handle nil or false values if the use case is to check contain? but it isn't my case so yea


I'm using the following to check if a map contains all the keys, does it help?

(defn keys-check [m & ks]
  (every? #(contains? m %) ks))

;;---------TESTING FNS----------
(deftest keys-check-test
  (testing "Basic test cases"
    (let [x {:a 1 :b 1 :c 2}

          y [{:a 1 :b 1 :c 2}
             {:a 1 :b 1 :c 2 :d 5}]]

      (is (true? (keys-check x :a)))
      (is (true? (keys-check x :a :b)))
      (is (true? (keys-check x :a :b :c)))
      (is (false? (keys-check x :d)))
      (is (false? (keys-check x :a :d)))
      (is (false? (keys-check x :a :b :c :d)))
      (is (every? true? (map #(keys-check % :a :b :c) y)))
      (is (false? (every? true? (map #(keys-check % :a :b :c :d) y))))
      (is (every? false? (map #(keys-check % :a :b :c :e) y))))))

George Silva17:11:19

Hello friends! I'm trying something here: I have a project that I'm starting off with clojure and I'll be deploying it on aws batch. This means this is going to be shipper as an docker image. For testing I would like to run tests and, some things, in docker. Also I don't want to miss on Calva. The tricky part is about environment variables. I configured environ and I have correctly set up the profiles, so locally, calva works just fine. However, for docker/docker-cmpose I'm using .env as a way of configuring the environment variables for the image. Is there a lean way of writing this only once and having access to the best of both worlds? Or should I just open up the REPL server in docker and allow calva to connect to it?


I think this is a common antipattern with clojure and docker. Don't dev inside docker, dev as normal, build an uberjar, package uberjar inside a docket contianer, done

George Silva15:11:50

Yea thanks! I'll follow that route for now!


Hi. I've decided to start thoroughly studying the clojure standard library. Thus I'm looking for advice on how to approach it. Which resources did you use/are you using for this purpose? I'm thinking I should just read clojure-docs, source code and usage examples for every core function. Do you think there is a better way? Any resources that are worth noting? I came across "Clojure the essential reference", but wasn't able to find a free copy anywhere, so it's not really an option for me.


I learned it by utility by just googling generic questions like "how do I remove various keys from a map?" whenever I ran into a problem, until I got a hang of the ones I commonly use. also is your friend.


i went through clojure cheatsheet and (source foo) on all of it.

👍 1

@U1Z392WMQ Yep, that's what I'm probably going to do.