Fork me on GitHub
#meander
<
2020-07-22
>
ikrimael04:07:38

i have to say getting to not having to lookup syntax with meander is chefs kiss

ikrimael04:07:13

it's making datashaping and refactoring a lot less of a chore (both in writing complex nested joins/extractions and being able to read it 5 days later instantly)

ikrimael04:07:56

the current part i'm trying to unravel is how the memory variables work, specifically in the context of joins

ikrimael04:07:05

--------------------------------- for ex, how to convert this into meander:

Jimmy Miller12:07:37

At least for me, your example of what you want to convert does not show up here.

3
ikrimael06:07:17

oops; forgot to actually paste

ikrimael06:07:11

sigh, now I forgot the exact context which I was asking around. let me circle back after I hit it again (won't be long since it's a top 3 pattern I keep hitting)

ikrimael08:07:28

(m/match
 [{:type   "Operator"
   :fields [{:type "int32" :name "age" :meta [[:uiSlider 1 100] [:tooltip "MyTool"]]}
            {:type "uid_t" :name "id"  :meta [[:hidden]]}]}
  {:type   "Graph"
   :fields [{:type "vec<int32>" :name "nodes" :meta [[:hidden]]}
            {:type "graphDesc"  :name "meta"  :meta [[:hidden]]}]}]

  [[{:type !type :fields ?flds} ...]]
  (;; Can't use meander syntax to rewrite/pattern match inside of ?flds and have to resort to let destructurings
   )
  
 [[{:type !type :fields [{:type !fldtype :name !fldname :meta !meta}  ...]} ...]]
  (;; !fldtype,!fldname,!meta are no longer "grouped" together to the type they were in
   ))

ikrimael08:07:43

so this is the problem distilled down

ikrimael08:07:50

what I "discovered" last night is using (m/cata) to recurse down and creating a pattern match term for each "nesting level"

ikrimael08:07:14

it's a decent compromise but i'm left wanting: - separating out to different terms erases context of which nested terms are allowed to appear where - found it harder to debug, both along user syntax errors and logic. What i'd end up doing is replace each pattern match term one by one starting from the top until i found which nesting level had an issue, then proceed from there

ikrimael08:07:03

some mitigations to issues above: - discovered datawalk which has been a godsend and made the above process a lot less painful - since the nesting match terms are all together, it's not that bad. instead of instant grokking of the code, maybe it's 5-10 mins as one mentally reconstructs which terms are allowed to go where

ikrimael08:07:47

as a real world ex: here's the code from last night: https://gist.github.com/ikrima/0353f3f1600a639797c63b2692c63334

Jimmy Miller14:07:42

I'm not 100% sure I followed all of what is going on. I think from what I do understand that you are probably doing the right thing by using cata. That is how we often deal with complicated patterns that need a fresh context for nested matches.

ikrimael19:07:02

ah, here's the simplified example with an addition of something along the lines of what i'm reaching for

(m/match
 [{:type   "Operator"
   :fields [{:type "int32" :name "age" :meta [[:uiSlider 1 100] [:tooltip "MyTool"]]}
            {:type "uid_t" :name "id"  :meta [[:hidden]]}]}
  {:type   "Graph"
   :fields [{:type "vec<int32>" :name "nodes" :meta [[:hidden]]}
            {:type "graphDesc"  :name "meta"  :meta [[:hidden]]}]}]

  [[{:type !type :fields ?flds} ...]]
  (;; Can't use meander syntax to rewrite/pattern match inside of ?flds and have to resort to let destructurings
   )

  [[{:type !type :fields [{:type !fldtype :name !fldname :meta !meta}  ...]} ...]]
  (;; !fldtype,!fldname,!meta are no longer "grouped" together to the type they were in
   )

  [[{:type !type :fields [{:type ?fldtype :name ?fldname :meta ?meta :as !fields}  ...]} ...]]
  (;; natural grouping in a concise way
   ))

noprompt19:07:13

That’s great experience report to hear @e749 🙂

noprompt19:07:36

The 5 days later bit especially. In the early days when I was sketching out what I wanted to do that was one of the problems I wanted to address.

noprompt19:07:27

Cause, you’re right, you often have to slow down, parse everything, and evaluate it in your mind when you come back to it. And it’s easy to end up with code like that when you’re in that “write only” mode, just trying to get an idea out of your head or some damn thing to work already.

☝️ 3
ikrimael19:07:02

ah, here's the simplified example with an addition of something along the lines of what i'm reaching for

(m/match
 [{:type   "Operator"
   :fields [{:type "int32" :name "age" :meta [[:uiSlider 1 100] [:tooltip "MyTool"]]}
            {:type "uid_t" :name "id"  :meta [[:hidden]]}]}
  {:type   "Graph"
   :fields [{:type "vec<int32>" :name "nodes" :meta [[:hidden]]}
            {:type "graphDesc"  :name "meta"  :meta [[:hidden]]}]}]

  [[{:type !type :fields ?flds} ...]]
  (;; Can't use meander syntax to rewrite/pattern match inside of ?flds and have to resort to let destructurings
   )

  [[{:type !type :fields [{:type !fldtype :name !fldname :meta !meta}  ...]} ...]]
  (;; !fldtype,!fldname,!meta are no longer "grouped" together to the type they were in
   )

  [[{:type !type :fields [{:type ?fldtype :name ?fldname :meta ?meta :as !fields}  ...]} ...]]
  (;; natural grouping in a concise way
   ))