Fork me on GitHub
#clojure-bay-area2021-02-10
>
sekao05:02:05

hey all, i just woke up :D 6am in oslo. if you're interested, here are the slides from the talk https://github.com/oakes/bay-area-odoyle i couldn't be bothered to use slide software like a normal person so i made it in the form of a play-cljc game

πŸ™ 4
❀️ 6
πŸ˜‚ 3
quantisan05:02:09

@youngil if you have a chance, could you post an example of what you meant about functional style looking like a graph tree (sorry, paraphrasing maybe incorrectly)? I'm interested in different styles of Clojure code/thinking.

Young-il Choo20:02:47

Sure. I mean something like: (f1 (f2 x (f4 y)) (f3 (f5 a b) (f6 c d))) which doesn't have a simple rewrite using ->, as opposed to (f1 (f2 (f3 (f4 (f5 (f6 x))))))

quantisan23:02:41

I see. This happens all the time. Taking (f5 a b) as a simplistic example, I would in-line that with (partial f5 a b) such that the whole block can be rewritten as a ->. Thoughts?

Young-il Choo04:02:10

Not sure what is achieved by (partial f5 a b). Would you mind reformulating my (f1 (f2 x (f4 y)) (f3 (f5 a b) (f6 c d))) using the ->?

quantisan07:02:36

oh my bad, I misread. which does highlight why that is hard to read though. 😜 here's my attempt to make it clearer, I'm a fan of descriptive fn name and arguments. So first step is to wrap the whole thing with a descriptive fn name and name each of the args in a map. Using a map as the arg here so we don't need to remember the arity and positions. And then making use of let to name results of f2 and f3.

(defn f1-with-clear-name
  [{a-named :a
    b-named :b
    c-named :c
    d-named :d
    x-named :x
    y-named :y}]
  (let [named-f3 (f3 (f5 a-name b-name) (f6 c-name d-name))
        named-f2 (f2 x-named (f4 y-named))]
    (f1 named-f2 named-f3)))
Which goes back to what you were saying about imperative style isn't necessarily bad. Took me a bit to realize what you were saying. But thanks!

Young-il Choo19:02:54

Agreed that nesting of function calls is harder to read. So, naming the arguments in a let is fine. The only down side is that it does make it look like sequential actions even though it may not be. It may be a matter of getting used to the nested expressions, but I realize that the Clojure convention is to prefer not to nest deeply.

Vincent Cantin06:02:50

@sekao That was a very interesting talk which made it clear that a rule engine is very useful in the front end.

ghosttoaster16:02:10

https://github.com/oakes/odoyle-rules this morning and am brimming with ideas for static blogs and games. Can’t wait to try it out.

πŸ‘ 4