Fork me on GitHub
#clojure-europe
<
2022-03-23
>
pez06:03:38

Good morning! update-vals 🎉

slipset06:03:07

Morning! In Bergen for an IRL conference.

🎉 3
ordnungswidrig07:03:21

Here comes the sun... Good morning!

dharrigan07:03:04

Good Morning!

dharrigan09:03:03

I'm still trying to understand/appreciate the change in Clojure 1.11 with regard to the keyword argument functions now also accepting maps

mccraigmccraig09:03:03

i have historically never used keyword-args fns, because it's been hard to pass on the keyword-args to other functions this change makes it easy to pass on the keyword-args to other functions (because you can now pass the gathered map on), so it enables easier composition of keyword-args fns, which makes keyword-args fns much less awkward to use and more attractive to me

mccraigmccraig09:03:58

the 1.11 ns option :as-alias , to allow namespace aliasing for qualified keywords without actually loading namespace, really scratches an itch for me too

thomas10:03:42

maybe an example of the keyword-args?

dharrigan11:03:24

Yes, that's the one. TBH, it's still not 100% clear to me.

dharrigan11:03:22

is it saying that :a 1 at line 4 (I'm counting top down), is put automatically into a map for me?

borkdude11:03:13

@U11EL3P9U AFAIC, the only thing to remember is: write functions that use map destructuring and pass maps to those. The old style & {:keys [ ... ] have been made compatible with passing single maps.

user=> (defn bar [& {:keys [a b c]}] [a b c])
#'user/bar
user=> (bar :a 1 :b 2 :c 3)
[1 2 3]
user=> (bar {:a 1 :b 2 :c 3})
[1 2 3]

👍 2
❤️ 1
dharrigan11:03:22

Time to break out th repl and have a play 🙂

dharrigan11:03:55

(defn foo
  [funky & {:keys [a b c] :as opts}]
  (str "funky = " funky ", a = " a ", b = " b ", c = " c ", opts = " opts))

(foo "foo" {:a 1 :b 2 :c 3}) ;; "funky = foo, a = 1, b = 2, c = 3, opts = {:a 1, :b 2, :c 3}"

(foo "foo" :a 1 :b 2 :c 3) ;; "funky = foo, a = 1, b = 2, c = 3, opts = {:a 1, :b 2, :c 3}"

dharrigan11:03:34

so, it works only with varadic functions, and it takes the varardic data and shoves it into a map for convenience.

mccraigmccraig11:03:57

you've been able to do that for ages @U11EL3P9U - the new thing is that you can also pass a map at the end of your keyword-args and it will be merged with the keyword-args for destructuring

dharrigan11:03:46

oh I see, thank you.

dharrigan11:03:32

Like this (foo "foo" :a 1 {:b 2 :c 3}) ;; "funky = foo, a = 1, b = 2, c = 3, opts = {:a 1, :b 2, :c 3}"

dharrigan11:03:44

Where the :b: and :c are merged in

mccraigmccraig11:03:53

zakly. and that means that you can take your destructured opts and easily pass them on to another fn which does the same keyword-arg destructuring, which you could not do easily before (you would have had to do something like (apply other-fn ... opts), which i find pretty horrid), so now you can have your keyword-arg 🍰 and eat it

😋 1
dharrigan09:03:20

Anyone care to educate a novice?

genRaiy10:03:32

good morning

borkdude10:03:59

goat moaning!

🐐 2
maleghast12:03:56

Morning Everyone!

reefersleep12:03:40

Good morning!

dharrigan14:03:08

Man! github down again

thomas14:03:50

yeah third time in last two(?) weeks or so

thomas15:03:32

it works again for me

orestis16:03:34

Just as I moved some checks from Travis to GitHub actions…