Fork me on GitHub

Pretty disappointed that doesn't seem to have any active Clojure mentors


@kamuela I asked about this on Reddit recently and someone who responded to a similar comment I made promptly signed up to be a mentor and approved my first exercise. So there is at least one person. But in the time between opening the thread (which was about programming challenge sites in general) that eventually led to that comment, and the approval, I lost interest in exercism.


What about Project Euler or Advent of Code?

Drew Verlee03:04:12

@kamuela maybe #code-reviews would be helpful? Are you looking for help?


(defn fib [] (lazy-seq (cons 0 (cons 1 (map + (fib) (rest fib)))))) why is it not possible to define a lazy fibonacci sequence like this?


just a small tweak and it works - you have to put the lazy-seq around map which I think defaults to evaluating in chunks of 32


(defn fib []
  (cons 0 (cons 1 (lazy-seq (map + (fib) (rest (fib)))))))


oh, I also forgot to eval fib in (rest (fib))


yup, also notice that this method is really inefficient and has to recalculate (fib) twice with each additional element

👍 4

check this out 🙂

(declare fibs)
(def fibs (#(list* 0N 1N (lazy-seq (map + fibs (next fibs))))))


Is defonce the equivalent of declaring a constant in other languages?


I believe it’s closer to or-equals (`||=` in ruby)


it’s a little subtle because it’s mostly used for keeping state around when you are re-evaluating things from the repl.


Got it, thanks


I feel useful 🎉


When working with a DB, is it more common to pass the connection object as a arg to every function that makes db calls or to have a global connection object?


or maybe make a function that returns the connect object and call that function inside every function that makes a db call


that way they are no side effects until a function is called

Lennart Buit17:04:09

I prefer passing the connection as an argument. I personally do lifecycle management with Stuart Sierra’s component library, which works badly with global ‘state’.

Lennart Buit17:04:46

Having no global ‘state’ or connection makes testing easier too, can just mock the first argument


I think it’s more commonly idiomatic these days to pass in explicit args absent other considerations, but there is a principled minority in the mount camp that don’t eschew storing state in vars. Among the constraints of the latter is that you’re locking yourself into only having one e.g. connection, at least at a time, which many find problematic but can be a reasonable choice for many projects. I’m in the component camp myself in general.


that seems addressable with a slight plot twist: pass around a connection pool/factory instead.