Fork me on GitHub
#beginners
<
2015-10-07
>
tim.mccarthy20:10:53

I’ve got a map with some values and I’m trying to calculate a bunch of derived values (that can depend on each other) and add them to the map. Is there any more elegant/idiomatic way than a giant let with a giant assoc?

danielcompton20:10:29

(defn example [m]
  (let [{:keys [a b c]} m]
    (merge m
      {:x (some-func a b)
       :y (some-func-2 b c)
       :z (some-func-3 x y)})))

danielcompton20:10:55

or

(defn example [m]
  (let [{:keys [a b c]} m]
    (assoc m
      :x (some-func a b)
      :y (some-func-2 b c)
      :z (some-func-3 x y))))

tim.mccarthy20:10:35

oh cool, I didn’t realize merge/assoc would create bindings like that

tim.mccarthy20:10:06

hmm, that doesn’t actually seem to work

tim.mccarthy20:10:20

(merge {} {:x 1 :y (inc x)}) just complains about “unable to resolve symbol: x"

alexmiller20:10:44

yeah, that's not a thing :)

beppu20:10:34

@tim.mccarthy: A bit of a tangent, but depending on how many derived values you're dealing with, something like javelin might suit your needs. https://github.com/hoplon/javelin

tim.mccarthy20:10:49

it’s less than 10, so I think it’s probably OK to bite the bullet and do the ugly thing rather than pull in a dependency, but that is pretty cool

gadfly36122:10:25

Is there any good reference material for setting up orgmode to run clojure source blocks?

beppu23:10:42

@gadfly361: I took the easy way out and used emacs-live as my base. http://overtone.github.io/emacs-live/

gadfly36123:10:56

Thanks! Emacs live is pretty slick! Just updated my question to ask more specifically about clojure source blocks in orgmode, have you had success with that before?

beppu23:10:21

@gadfly361: I've never tried doing that. Sorry.

gadfly36123:10:08

No worries, thanks for the link tho!