Fork me on GitHub

I have noticed a convention of using user.clj which requires in a dev.clj ns like Does anyone know why this is done vs. keeping everything in user.clj?


user.clj is auto-loaded by clojure if it's on the classpath


dev.clj isn't "magic" in that way, so you have more direct control of when / whether it is loaded


It means you can avoid any/all dependencies that dev.clj needs (as long as you don't call (dev)). So you can isolate dev dependencies from "regular" dependencies.


I think the only thing I've ever used user.clj for is auto-compiling a namespace that uses :gen-class to generate a Java class from Clojure code, which the rest of the project relies on.


and as an aside, the idiom I've learned for (require 'foo) (in-ns 'foo) is (doto 'foo require in-ns)

metal 11

Ah, yes, nice.


easily augmented to (doto 'foo-test (require 'foo :reload) (clojure.test/run-tests)) when iterating on tests - it's still one line which is nice when using repl history


Ahhh, makes sense.


@seancorfield You mentioned you only use user.clj for the :gen-class use case. Does this mean that for your projects, you don’t setup a user -> dev reloaded workflow?


I never use any sort of automated reload/refresh workflow.


I eval every change, as I make it, directly into my running REPL and I run a REPL for many days, sometimes even weeks.


nirvana 😄

Alex Miller (Clojure team)03:06:49

+1 to seancorfield - I do the same thing as Sean and have never used the reload/refresh workflow either. I understand how that came to be a thing but I think you can get many of the same benefits in other ways that don't need that.

Alex Miller (Clojure team)03:06:17

if you spend some time in the clojure code base, user.clj is deeply weird and different than how every other thing is loaded in Clojure. I prefer to write dumb boring code that does obvious things and invoke it when I want to run it.


I have not asked, but I suppose that one property of Sean's approach is that if you ever forget to re-eval a modified function, then the JVM state and source file state now differs, so it does require some pretty tight discipline. Perhaps an attractiveness of a reloaded workflow style for some developers is the belief/hope/often-true aspect that it keeps these things in sync automatically?

Alex Miller (Clojure team)03:06:29

I frequently reload the particular namespace I'm in

Alex Miller (Clojure team)03:06:19

you can still get out of sync if you've removed things in the code but they're loaded in memory. I rarely find that to be an issue and since I'm constantly evaluating things.


Where can I read more about this "automated reload/refresh workflow"? Is it what's described here?


To Alex's point about things remaining in memory after you've removed them from code, even if you reload the namespace, I have ctrl-; r bound to remove-ns but I only use it very occasionally because you can still have references to that code compiled elsewhere so it's sort of the "nuclear option" (and it's part way toward those refresh/reloaded workflows I try very hard to avoid).


I also have ctrl-; R bound to require ,,, :reload-all for the current namespace. Again, it's a bit of a "nuclear option" that I try to only use as a last resort. Both remove-ns and :reload-all can cause a ripple effect, depending on how much code you have in memory.


I tend to edit, ctrl-; B (evaluate top-level block/form), repeatedly as I'm working -- without even saving a file -- trying stuff out with expressions inside comment forms ("Rich Comment Forms" per Stu H), switching between files as I work, developing and testing code, developing and testing tests, etc. Once I have a "feature" working in memory, in the REPL, I'll pop into a terminal window and run a subset of the test suite to just verify I don't have passing tests in memory due to leftover "cruft". If that small feature works, then it's git add/commit/push to branch. Rinse and repeat.


I also make heavy use of Cognitect's REBL while I'm working, both to visualize data and to "visualize code" -- I have a bunch of keys bound to commands that submit various things to REBL so I can browse namespaces, Var uses, even ClojureDocs and Java API docs directly in REBL (since it renders .URL objects as HTML web pages -- and then you can navigate around with your current and previous pages showing, side-by-side).


I work in the REPL but have setup a namespace to invoke tools...refresh (can’t remember the exact namespace) to remove everything and go back to source files. Useful if you mess something up real good, when switching branches, to just sanity check if something appears off.


@orestis So you consider it a "last resort"? (I hope)


Yes, a last resort for unusual circumstances


I use it all the time, fight me :)


I work with a lot of web handlers though, which close over state and are difficult.


Despite reading all that I saw from time to time on the topic, I still fail to see the appeal of manual reloading. To me, it's like driving a stick. Needless to say, I got a driving license only for an automatic. :)


"fail to see the appeal of manual reloading" -- control and simplicity.


(I'd much rather drive a stick shift!)


(esp. when that was a 5L Mustang Cobra 🙂 )


Sorry, a correction: "... of manual reloading at all times". I understand the occasional need, and even I do use that (but only if the automatic reload didn't get those pesky defrecords). But all of the time? Nooo, let the system take the wheel.


I think this is not directly connected to Clojure, but I stuck with this. I was trying to get help in more cloud specified community, but without success. Maybe somebody here know solution:

curl -H "Content-Type: application/json" -d '{"foo":"bar"}' -X GET 
curl: (92) HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)
http-kit logs
Thu Jun 11 13:23:15 CEST 2020 [client-loop] ERROR - select exception, should not happen
java.lang.IllegalStateException: Client/Server mode has not yet been set.
	at java.base/
	at org.httpkit.client.HttpClient.finishConnect(
	at java.base/
Thu Jun 11 13:23:15 CEST 2020 [client-loop] ERROR - select exception, should not happen
java.lang.IllegalStateException: Client/Server mode has not yet been set.
	at java.base/
	at org.httpkit.client.HttpClient.finishConnect(
	at java.base/
but exactly the same code in the same docker image works in my local environment. The issue is about -d '{"foo":"bar"}'. Without this:
curl -H "Content-Type: application/json" -X GET 
not found⏎
^ expected result AFAIK google cloud run use HTTP/2. Does it change anything? Any hints what I can do wrong? In metric and logs I see google cloud run break this connection before it goes to the docker container. This is something about network protocol probably. But it doesn’t work for me in http-kit client and in curl. hmm. No idea what to do with this.


I also found this works with POST, but not with GET


well I have no idea, but it looks HTTP/2 send request GET with body is not something valid. At least in google cloud.


can you send the request without body?


get with body really isn't something you should be doing


I need to send a data, I will switch to POST


but this doesn’t effect any state


GET request is not expected to have body according to HTTP spec


still very strange error from server, I see this first time


yes, that is pretty cryptic


what’s the easiest, tersest way to update a map with default values for keys that are nil?

Alex Miller (Clojure team)14:06:38

well I'd put my effort into not putting nils in the map in the first place then (merge defaults the-map)

Ben Grabow14:06:22

If for some reason you really need the nils, you can do (merge-with defaults the-map (fn [default-val val] (if (some? val) val default-val)))


Is there a way to use into along with a transducer that has two input sequences? For example:

(into [] (mapcat vector) [:x :y :z] [1 2 3])

Alex Miller (Clojure team)16:06:14

the only transducing context that takes multiple inputs is sequence

Alex Miller (Clojure team)16:06:59

conceptually, there is no reason this couldn't exist (and the guts are already there, as used by sequence) - but the arities collide in all the existing sequence functions like map and mapcat

Alex Miller (Clojure team)16:06:19

the existing map transducer (and thus also mapcat, as it's just a composition of map and cat) does support multiple inputs, that's just not exposed through into etc


Ok, thanks for explaining 👍

Drew Verlee18:06:38

whats the ideal way to write a clojure data stucture to an .edn file? it seems like i should use pr-str then spit. but i dont see anything definitive on the subject. just trying to avoid any gotchas. bonus points if there is a way to save it in a formatted way...


pprint takes a writer arg

Alex Miller (Clojure team)18:06:46

Or re-bind *out* around pprint

Eduardo Mata20:06:27

I am using boot instead of lein. I was used to doing lein ancient to check outdated dependencies. What could I use to get the same result in boot?


boot show --updates i believe

✔️ 3