Fork me on GitHub
#beginners
<
2017-12-23
>
Sabbatical201702:12:41

@noisesmith @scot-brown @flowthing @admay Thank you very much for your comments! I found this discussion very illuminating.

Sabbatical201703:12:35

@noisesmith @scot-brown @flowthing @admay @alexmiller For the record, I have come up with a solution using datascript that I consider very easy to read and reflecting my intent very well: (datascript.core/q '[:find ?a (min ?b) :in [[?a ?b] ...]] x). This returns ([2 2] [0 0] [1 1]) as required (here, as before, I used x to denote [[0 0] [0 1] [1 1] [1 2] [1 3] [2 2]].) The only drawback is that the datascript query takes 47 microseconds to run, as opposed to the 5 microseconds in scot-brown's neat ->> suggestion, but it seems still plenty fast enough for me.

amit588109:12:57

i have [{:a 1 😛 1} {:a 2 😛 2} {:a 3 😛 3}] and [{:c 1} {:c 2} {:c 3}] and i want [{:a 1 😛 1 :c 1} [{:a 2 😛 2 :c 2} [{:a 3 😛 3 :c 3}] ??

amit588109:12:18

😛 refers to ": b"

schmee09:12:01

@amit5881 use three backticks (`) to wrap blocks of code

schmee10:12:05

here’s one way to do it:

user=> (def a [{:a 1 :b 1} {:a 2 :b 2} {:a 3 :b 3}])
#'user/a
user=> (def b [{:c 1} {:c 2} {:c 3}])
#'user/b
user=> (mapv merge a b)
[{:a 1 :b 1 :c 1} {:a 2 :b 2 :c 2} {:a 3 :b 3 :c 3}]

Drew Verlee20:12:41

i’m doing a coding exercise where you have to refactor some intentionally (the writers knew better) code. The clojure version seems particuallry perverse, though i could imagine worse if you were trying to be hard to read. It really feels like someone would have to go out of there way to use so many atoms, for loops and do blocks though.

Naylyn23:12:04

That sounds like a great way to learn. Do you have a link you can share?

Drew Verlee01:12:51

i’m not sure i can actually, its a private repo. But I have seen this sort of thing before, the best example, and quite possible where the inspiration comes from, is the Gilded Rose by Sandi Metz. https://github.com/amckinnell/Gilded-Rose-Rubyhttps://github.com/amckinnell/Gilded-Rose-Ruby. Not clojure, but the idea is the same.

Drew Verlee01:12:52

I think a lot of people might find sandi’s approach to be simplistic, possible arguing that good abstractions can’t arise from simple refactors, but she makes a strong case that they can in 99 bottles. I would honestly be very interested to hear how other developers with different experiences took from that book.

Naylyn22:12:46

Thanks for the link, I'll check it out.