Fork me on GitHub
#beginners
<
2019-04-21
>
kamuela01:04:07

Pretty disappointed that http://exercism.io doesn't seem to have any active Clojure mentors

tabidots02:04:53

@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.

tabidots02:04:14

What about Project Euler or Advent of Code?

drewverlee03:04:12

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

nicholas.jaunsen13:04:18

(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?

qythium13:04:24

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

qythium13:04:45

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

nicholas.jaunsen13:04:55

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

qythium13:04:14

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

qythium13:04:10

check this out 🙂

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

somedude31414:04:47

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

hobosarefriends14:04:38

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

orestis04:04:43

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

somedude31414:04:22

Got it, thanks

hobosarefriends14:04:44

I feel useful 🎉

lockdown-17:04:55

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?

lockdown-17:04:07

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

lockdown-17:04:36

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

donaldball20:04:35

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.

jerry.hebert20:04:42

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