clojure-europe

For people in Europe... or elsewhere... UGT https://indieweb.org/Universal_Greeting_Time
dharrigan 2020-12-01T06:40:12.260900Z

Good Morning!

plexus 2020-12-01T06:41:15.261100Z

Good morning!

plexus 2020-12-01T06:41:27.261400Z

@otfrom google-apps-clj works fine https://gist.github.com/plexus/8969044e84bda06b4e85d8e33a868720

2020-12-01T09:18:54.264600Z

awesome. thx!

plexus 2020-12-01T06:41:52.261800Z

https://github.com/SparkFund/google-apps-clj

thomas 2020-12-01T07:59:58.262400Z

moin moin

simongray 2020-12-01T08:00:51.262700Z

godmorgen

2020-12-01T09:18:59.264900Z

morning

synthomat 2020-12-01T09:48:35.265300Z

Moin!

raymcdermott 2020-12-01T10:10:46.265600Z

morning ... mood

borkdude 2020-12-01T10:19:50.266500Z

Morning! Welcome to join the London Clojurians meetup tonight, where'll be showing some internals of babashka and sci. https://www.meetup.com/London-Clojurians/events/274014078/

ordnungswidrig 2020-12-01T10:25:38.266800Z

Good morning!

ordnungswidrig 2020-12-01T10:26:00.267100Z

The view from my shower :rolling_on_the_floor_laughing: 🙈

dharrigan 2020-12-01T10:27:22.267700Z

I call that a snow-day. Grab a snowboard/skis and hit those slopes!

borkdude 2020-12-01T10:38:46.269100Z

I revisited some code in sci and thought: what the hell did I do here. Perf gain my ass. Then I checked it:

user> (time (dotimes [i 1000000] (let [expr '(1 2 3) cond (first expr) expr (rest expr) then (first expr) expr (rest expr) else (first expr)] [cond then else])))
"Elapsed time: 119.671576 msecs"
nil
user> (time (dotimes [i 1000000] (let [[cond then else] '(1 2 3)] [cond then else])))
"Elapsed time: 744.034037 msecs"
nil
Yeah, indeed, that's a perf gain. Sequential destructuring costs more than manually writing things with first and rest. 🤷

jasonbell 2020-12-01T11:35:09.269400Z

Morning

dominicm 2020-12-01T11:45:06.270100Z

I thought destructuring expanded to the same thing

borkdude 2020-12-01T11:52:12.270400Z

Destructuring expands to nth calls on the vector

borkdude 2020-12-01T11:52:48.270600Z

user=> (destructure '[[cond then else] '(1 2 3)])
[vec__34112 (quote (1 2 3)) cond (clojure.core/nth vec__34112 0 nil) then (clojure.core/nth vec__34112 1 nil) else (clojure.core/nth vec__34112 2 nil)]

borkdude 2020-12-01T11:53:39.271200Z

huh, no, it expands to nth calls on the thing you destructure on, and nth for lists isn't so perfect for this since that's an O(n) operation

borkdude 2020-12-01T11:56:49.271600Z

user=> (time (dotimes [i 1000000] (let [[cond then else] [1 2 3]] [cond then else])))
"Elapsed time: 65.380112 msecs"
nil
user=> (time (dotimes [i 1000000] (let [[cond then else] (list 1 2 3)] [cond then else])))
"Elapsed time: 1181.079782 msecs"

borkdude 2020-12-01T12:00:20.272600Z

But the cost of turning a list into a vector should also be taken into account:

user=> (time (dotimes [i 1000000] (let [[cond then else] (vec (list 1 2 3))] [cond then else])))
"Elapsed time: 572.364397 msecs"
so all in all, doing first + rest might be the optimal destructuring for lists

dominicm 2020-12-01T14:12:10.272700Z

So it has to reiterate the list each time. Interesting. That seems like an opportunity for destructure to get smarter.

dominicm 2020-12-01T14:12:49.272800Z

Although, I'm a terrible human being who parses the destructure output: https://github.com/juxt/clip/blob/eb5bef08d9ddc4d39c9084ab123b02b90f9b177a/src/juxt/clip/core.cljc#L146 😂