Fork me on GitHub

many thanks @didibus I still want to get to the bottom of the general rule of whether to mutate/decorate the original object argument or to return a new object with key references to components of the original object argument


Ok, I profiled it. Interestingly enough, fooAA is the quickest.


wow - more than twice as fast


I'm not sure what to make of it. I was expected fooBB to be faster and my questioning was "by how much". I have always thought that instantiating a new object is always more expensive than just editing the properties of an existing object


Unclear, when I look at the code, they actually seem kinda similar. Since there's only 3 elements in the map. It is a PersistentArrayMap under the hood. Get only does an indexOf and returns the array element. And then {} calls createAsIfByAssoc. While update just calls get, which should be the same performance. And then calls assoc. Which is pretty similar the createAsIfByAssoc. But I'm guessing there might be some minute difference.


Only difference I can see is assoc calls clone, while createAsIfByAssoc does a loop to copy over the data on its own.


Note that with Clojure's immutable collections, 'editing the properties of an existing object' is actually 'creating a new object that shares hopefully most of the contents of the original, but it depends on the editing you are doing'


When the operation is done, the original and the 'modified' versions are both accessible and usable in your code. Nothing has been modified in place.


My head was in the gutter


fooBB creates a bunch of intermediate maps


So its obviously slower


Any good articles or books on application Design and architectures in clojure and functional languages in general.


@U1CUUKHDL A really good one although quite short and focused mostly on polymorphic aspects is

馃憤 4

And perhaps Clojure Applied

馃挴 4

Thanks for the suggestions


While fooAA creates a single map


@mcferren I think I figured it out. fooAA creates a single map. So it gets 3 values out of the map, increment, and then creates one new map with the new values. fooBB will get one key of the map, increment it, and then create an intermediate map with only the first key updated. Then, from this map, it will grab the second key, and increment that, and create anther map, etc. So in the end, it has to create 3 maps, while fooAA only has to create one.


Other variants that might be faster: Rely on bar being reducible:

(defn fooCC [bar]
  (reduce-kv (fn [m k v] (assoc m k (inc v))) {} bar))
Same, but make the accumulator transient:
(defn fooCC' [bar]
  (persistent! (reduce-kv (fn [m k v] (assoc! m k (inc v))) (transient {}) bar)))
Employ a transducer (which should involve a transient accumulator):
(defn fooDD [bar]
  (into {} (map (fn [e] [(key e) (inc (val e))])) bar))


From my bench reduce-kv is fastest. The transient versions don't seem to make a difference, and are even a bit slower. But, that was tested on a small map with a lot of iterations. I suspect the transient versions would start winning if the map was larger.


If the map is a constant though, inlining it like in fooAA with a macro is faster.


Yup, confirmed. Is the map is bigger, the transient versions start to perform better then the non transient versions.

Karol W贸jcik11:11:47

What is a correct way of spiting the clojure map to .edn file with indentation of 2?

Karol W贸jcik11:11:49

This is what I got so far

(with-open [writer ( "report.edn")]
    (clojure.pprint/pprint inserts-map writer)
    (println "Exiting...")))
The problem with this approach is that the data is truncated.


what REPL are you using?

Karol W贸jcik11:11:21

It鈥檚 not an issue in a repl. Rather the pprint truncates the data i think. I鈥檓 using cider


are you sure? try running (set! *print-length* nil) in your REPL and then run agian


pprint uses the default values of *print-length* and *print-level*, so if you set those to nil in your namespace you should be good:

Karol W贸jcik11:11:56

Thank you @U3L6TFEJF 鉂わ笍 You were totally right 馃檪


you鈥檙e welcome 馃槃


hey guys, I am looking for an SSE (Server Sent Events) Client library (like gniazdo for websockets) do you guys have any suggestion ?


Are there any open source Clojure libraries that you consider excellent examples of using the language that you would recommend reading through?

Toby Clemson14:11:56

@tkjone I have found browsing through anything by James Reeves (weavejester) really useful

馃憤 16

was just browsing through the Codox source a couple of days ago, very readable!

Surya Poojary16:11:17

Hello gentlemen

Surya Poojary16:11:36

Im new to clojure...

Surya Poojary16:11:50

A bit of python and ruby experience ..and a bit of java.

Surya Poojary16:11:01

Nice to meet ya'all


Hey @surya.malloc, live long and prosper!upside_down_parrot


Is there an easy way to change a leiningen project name and recursively change all it鈥檚 namespaces names?


pablore I think you could check out if have some support for that. Else I think you have to go full bash mode.

Surya Poojary16:11:54 should i learn clojure....i mean how to get cozy with ()


Google clojure for the brave


Search for jr0cket


GitHub modern cljs


Start with installing spacemacs


IM me if you need help with set up or writing hello world


Read through the official Reference and Guides at


Go through the exercises at


That's the best way to go about it at first

Eric Ervin01:11:59

I had a good time learning Clojure with the materials for Clojurebridge. Especially the material that uses Quil for a lot of interactive "hello square" "hello circle" examples.

馃憤 4
Eric Ervin01:11:22

I'd done this type of algorithmic drawing in other programming languages, so it was learning a new language in a domain I already knew.

Surya Poojary16:11:11

This is my first lisp lang

Surya Poojary16:11:17

And im very excited


my suggestion is since you have experience in programming already

馃憤 4
馃挴 4

Splitting up code that runs inside Core.Async go-blocks -> Seperate things in their own functions and write tests for thoose functions?

Surya Poojary16:11:01

How's clojure for gui


Take a look at Clojurescript, also there is: (React for CLJS) (A opinionated "Reagent" for CLJS(?) I like it.) etc.... If you want desktop-gui you can use re-frame with re-com and wrap it in electron, or use some java lib, think there are some clj-libs as well for that.

Surya Poojary16:11:50

JavaFx and swing ?


Did you try clojure Seesaw?


You can use those. But its best to use them with interop. That is, doing java fx in Clojure will feel pretty similar to doing it in java.

Adrian Smith16:11:17

how do I read a list of files from a given directory? I have pointed at a directory, when I evaluate it, it's a

#object[infinite_carers_checklist.core$cp_files 0x15a04efb "infinite_carers_checklist.core$cp_files@15a04efb"]
how do I go from that to something I can iterate on?


That looks like an fn generated inside cp-files

Adrian Smith16:11:38

yep that was my issue 馃檪


Hey Guys! I'm very new and I've started by going through a few tutorials and walk-throughs right now I'm working on and I'm having trouble connecting to the DB. I'm on Manjaro and I have postgres up and running on localhost:5432 with the db and user existing and having the right permissions (I can psql in).

(def db-spec
  {:dbtype "postgres"
   :dbname "restful-crud"
   :user "postgres"
   :password "postgres"})
(defn -main
  [& args]
  (models/set-root-namespace! 'restful-crud.models)
  (db/set-default-db-connection! db-spec)
  (run-jetty app {:port 3000}))
Gives me an error with a caused by that says
Caused by: java.lang.Exception: DB is not set up. Make sure to call set-default-db-connection! or bind *db-connection*.
	at toucan.db$connection.invokeStatic(db.clj:124)
	at toucan.db$connection.invoke(db.clj:117)
	at toucan.db$query.invokeStatic(db.clj:275)
	at toucan.db$query.doInvoke(db.clj:271)
	at clojure.lang.RestFn.invoke(
	at toucan.db$simple_select.invokeStatic(db.clj:379)
	at toucan.db$simple_select.invoke(db.clj:368)
	at toucan.db$select.invokeStatic(db.clj:641)
	at toucan.db$select.doInvoke(db.clj:635)


I've tried a few of the other arg map values suggested in the toucan guide but same error


@btenggren20 That looks like a very old-fashioned way to interact with a DB (using mutable global state for the connection) so I'm surprised that's a recent blog post....


...Ah, Toucan is trying to imitate an ORM...


Yeah it uses some magic and macros to let you specify a user schema


...I don't think that's a good approach, to be honest. Toucan doesn't look very idiomatic 馃槥


What are the more common ways of handling connection pools and running queries?


ls there like a default library?


People use c3p0 or HikariCP for connection pooling mainly. The docs have an example of the former


org.clojure/java.jdbc (aka is the "standard" JDBC library in Clojure (it's a Contrib library and it's the basis of pretty much everything else built around databases, including Toucan, which in turn seems to be based on / inspired by Korma).


Well alright! I'll give up on this. Although I did manage to make the connections work through the Repl


but not when I ran lein run


join #datomic


\join #datomic


sorry, third time's the charm.

Lennart Buit20:11:33

Its just like good ol鈥 IRC

Karol W贸jcik22:11:02

JVM noob here: Would highly appreciate if you could point me how to get rid of it during compilation?

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See  for further details.


you need to add some version of sl4j to your deps, or change something else so nobody is trying to use it


logging in java is a bit precious

Karol W贸jcik22:11:02

I鈥檓 trying to use exclusions like so:

[com.github.javafaker/javafaker "0.16"
but it does not work at all 馃槥


that's the opposite of what you need


you need to make sure some implementation is actually present


(or purge all the libs that try to use it)

Karol W贸jcik22:11:14

It鈥檚 very bizarre that I have to include some logging library to just make the compilation silent.


it's because the logging design in java is a mess


it's not part of the core language, and there were multiple competing implementations, and weird decisions made about how to compromise on this so libs can do logging

Karol W贸jcik22:11:21

I鈥檓 shocked

Karol W贸jcik22:11:15

Will definitely read it @noisesmith. Thank you very much 馃檪 I鈥檝e added the slf4j and it鈥檚 working perfect 馃檪 Btw where do Java guys search for the packages? I know that there is maven but is there something cleaner/with-examples/with-description like on npm website 馃槃?

Jp Soares23:11:08

Do you still recommend for learning? I'm bothered by the fact that I don't see clean code in the solutions.. I'm going through the exercises and looking for other's solutions to learn better approachs and more about the most used functions. What is bothering me is that I'm following a lot of people and I don't see mantainable code; code that one would commit in production; that's simple, easy and fast to understand. I see that the site value more the small code (code golf) than readablility. So I would like to know good references and examples of Clean Clojure Code, it would be perfect if you know some user with solutions like that.


I think this is 50/50. Some of the solutions are definitly going for cleverness. But I think 50% of it is because your eyes aren't trained to Clojure yet.


It takes some time to train your eyes to the syntax, but also the core functions, their meaning and semantics, how they compose together, etc.