Fork me on GitHub
#beginners
<
2023-09-16
>
vxe03:09:55

what's the current preferred tool/method to spin up a new clojure deps project that uses tools.build? thanks

Bobbi Towers04:09:49

I'm pretty sure deps-new does that: https://github.com/seancorfield/deps-new

👍 3
2
Felix Dorner20:09:44

How can I define a function that has an optional last argument which defaults to an empty map?

Bob B20:09:41

a common way is two separate arities, and the n-1 arity calls the n arity with the default value

Bob B20:09:25

as a contrived example:

(defn frob
  ([x] (frob x 5))
  ([x y] (vector x y)))
(frob 1 2)
=> [1 2]
(frob 1)
=> [1 5]

Felix Dorner20:09:43

I tried with associative destructuring and couldnt get it to work.

Bob B20:09:12

since the :or part of associative destructuring is in the map argument, it still requires the argument be passed - but with the n-1 arity, that can pass the empty map, which will cause the :or part of the destructuring to be used

👍 1
seancorfield21:09:38

(defn frob [x & [y]] ...) will give you y bound to nil if it isn't passed in which might be able to stand in for an empty map, depending on what you want to do to it.

seancorfield21:09:02

(but I generally prefer the multi-arity approach Bob suggested since it makes the default values clearer)

👍 2