Fork me on GitHub

I am hoping the clojure fam can help me out, there was an article (or maybe github project), that demoed running multiple versions of clojure side by side with classpath isolation, can anyone help me find it!?


@flyboarder it reminds me of immutant, but i'm guessing you mean something else


(and i didn't actually use immutant)


Looking for side-by-side, ie. in the same JVM


Was that boot pods @flyboarder ?


I am quite certain he would be aware of boot pods 😉

👍 4

What’s the correct pred for something like this?

(condp pred thing 
  map? [:map thing]
  vector? [:vector thing]
  string? [:string thing]
(Or a better solution that accomplishes the same thing)


Just #(%1 %2)?



(require '[clojure.spec.alpha :as s])

(s/conform (s/or :map map? :vector vector? :string string?) thing)

Alex Miller (Clojure team)10:06:00

Why not just use cond?

👍 4

Would a protocol be quicker?


Guys, how did you learn to solve problems the functional way? I’m currently in the middle of moving some of my JS codebase to Clojure. Started out by trying to directly rewrite the code, but that didn’t work and I sometimes still struggle to wrap my mind around how to design the flow of the programs. So I’m interested in hearing where you got this from


@henrik use a protocol if you want openness, if you have a constrained set of shapes you want to apply that on, go for cond as suggested by @alexmiller

👍 4
Suni Masuno12:06:44

@kyselyradek I'd love to hear other's approaches. But For me I got to functional designs a bit "backwards" learning some heuristic rules of software design and being led by them to functional. The rules I use, that got me here, are... 1) minimize and isolate mutation 2) ditto for side effects 3) ditto for state 4) Name what you are doing, not what you're doing it on (what around here I've found out is called point free) 5) A small amount of dense code is slightly better than a large amount of light code 6) write code first for other developers to read, second to do it's job 7) TDD, lots And that's a quick look at how I got here. Also some vids....;v=US8QG9I1XW0


Suni, thank you a lot for the answer! I’m looking at the point-free programming now, looks like that was mainly what I was missing. However can you please explain what you meant by > 5) A small amount of dense code is slightly better than a large amount of light code I have a slight idea, but just to make sure

Suni Masuno14:06:55

I find highly composed code (which is my fav!) "does more" per line. As a result I feel like 15 lines of "really good clojure" is effectively ~100 lines of "really good java". They're both good code, and most importantly it tends to take about the same amount of time to read or write them. in those situations I tend to prefer the option that produces more "dense" code.

👍 4

Right, that’s what I though you meant. Great, thanks a lot for your input on this! 🙂

Suni Masuno15:06:14

^_^ No problem! Glad I could help.


@kyselyradek Neal Ford has a video on “Functional Thinking” that I found helpful.

👍 8

hi, in ring or maybe even in general, what is the difference between :session and :cookies?


@tomaas cookies are literally the HTTP cookies, whereas session doesn't come from HTTP headers, but is something that can be derived (for instance, by looking up a session ID in a database)


oftentimes people use a cookie to lookup a session

Ahmed Hassan13:06:19

And cookies are stored in browser.


sorry, did not get it all well


session is created in server, but the browser must store something (id of session) so that with following requests the server can query up session data based on that id


cookies are often used to carry that ID


thank you!

Suni Masuno15:06:04

Does anyone have any advice on moving defs between namespaces on an existing project? People keep telling me intellij/cursive have cool features and I'd love it if this were one of them. But yeah, do you just go through and check aaaaalllllll the requires? (context, I found a bloated utils file and wanna break it up a fair bit)


is there a neater way to do this (that doesn’t involve swaping an atom 😛)?

(defn find-all
  "Recursively walks a tree structure and finds all elements
  that match `pred`. Returns a set of results."
  [pred tree]
  (let [results (atom #{})]
     (fn walker [x]
       (when (pred x)
         (swap! results conj x))


blend tree-seq and filter?


ahh, I always forget about tree-seq


I'm going through tempura's code and stumbled across this:

(let [;;; Local aliases to avoid var deref
      merge-into-default-opts merge-into-default-opts
      scoped                  scoped
      search-resids*          search-resids*
      search-resids*-cached   search-resids*-cached
      search-resids           search-resids]
Can someone please help me understand what the comment means?


My guess would be performance optimization. Any time you access a var, the compiler emits a call to <the-var>.deref(), which adds a layer of indirection plus a volatile read. A local binding is just an alias to a value, so it's easier for the JVM to optimize.


I see, thanks! I didn't know about <the-var>.deref().


actually the method name is not deref, it's getRawRoot


hey everyone, in a couple places in my code i’m trying to decouple services by passing functions as arguments as follows:

(defn get-and-do-a-thing [accessor args]
(do-the-thing (accessor args))


is there any good way to constrain the contract of the accessor function at this level?


not in a way that's enforced at compile time


you can use specs and exercise the accessor, which works if you remember to do so and the spec is correct


yeah, that’s what i thought. thanks


also, when would you use binding over with-bindings?


I'd only use with-bindings if something else ensured I had the vars available


otherwise binding does all the stuff to get the vars behind the symbols for me


And in general I avoid dynamic bindings


why’s that?


Because static scoping is good


And functions that take arguments are good


There are very good odds that anything that is a dynamic var is really a function argument hidden behind awkward calling convention

bellissimo 4

There are places were dynamic scope is useful, but like maybe less then one or two new instances of dynamic scope per code base. So maybe you introduce a single dynamic var, wrap it in some helpers, and use it while forgetting the mechanism that underpins it from the rest of your code that does nothing with dynamic scope


If you are using dynamic scope so often that you have to ask about preferring bindings or with-bindings, you might have a big ball of mud


yeah it’s mostly just one design decision that’s just come up, i’m trying to maintain an in-memory cache of something from a database, and the question arose because i didn’t know if it was even going to be thread safe


it doesn’t feel right intuitively but i’m trying to make a bit more of a concrete argument


/ learn about the purpose of dynamic scope i guess