meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
ikrimael 2020-07-26T15:58:53.263200Z

+1 on group by; @jatkin how're you using m/gather? i couldn't get it to work the way i thought it would (i.e. with maps)

JAtkins 2020-07-26T16:00:04.263800Z

(m/search [{:a :whatever :b [{:n 1} {:n 2} {:n 1}]}
             {:a :goes :b [{:n 1} {:n 2} {:n 4}]}
             {:a :here :b [{:n 2} {:n 2} {:n 3}]}]
    (m/scan {:a ?a :b (m/gather {:n !n})})
    {:a ?a :n !n})
This did an ordered powerset of n

🤯 1
ikrimael 2020-07-26T16:01:05.264Z

imho, that's a great candidate to go into the cookbook

JAtkins 2020-07-26T16:01:36.264500Z

Sure - only thing is I don't fully grok why this did what it did

ikrimael 2020-07-26T16:01:51.264800Z

haha, neither do I. i'm playing with it right now

jimmy 2020-07-26T16:05:28.265800Z

The gather there wouldn't be necessary. On my phone but you should be able to do [pattern ...]

JAtkins 2020-07-26T16:07:43.266500Z

Yup, you are right

jimmy 2020-07-26T16:08:00.267100Z

Gather is filter for pattern matching. Given a pattern it will go through a sequence and find all the elements that match ignoring the others.

JAtkins 2020-07-26T16:08:19.267400Z

Oh --- and that's how I got a powerset

JAtkins 2020-07-26T16:08:42.267700Z

well, got 2 things to add now

ikrimael 2020-07-26T16:09:45.267800Z

some thoughts from weekend code sesh where i ended up rewriting a lot of meander matching: handwavy/food for thought: - cata is really powerful especially on the right hand side. - i can almost write shape morphing functions fluently which is a joy (i.e. don't need to lookup syntax and I can write it in one go) - but debugging is such a pita when i get something wrong that i found myself psychologically building stuff out much slower and more methodically. just odd irrational human behavior so only verbalizing it as food for thought - not really sure what's actionable here bc highlighting cata more upfront would probably showcase value earlier on but that's me looking at it with the "curse of knowledge" bias in that i understand the syntax enough. more concrete thoughts: - i find myself wanting to construct or extract a key out of a map alot with m/rerwrite but doing it inside of meander is frictive enough that i end up cheating and adding (let [helperfn .....])

💯 1
ikrimael 2020-07-26T16:12:29.268Z

can you elucidate on how this is different than the "normal" way? ex: [ (m/app bla) ...] or [pattern ...] also is it meant to be used with maps?

jimmy 2020-07-26T16:17:01.268200Z

It is used on seqables. Gather is often used with pred. So you could use gather with (m/pred even?) To gather up all the even numbers. Where as doing it with ... would require everything to be an even number.

jimmy 2020-07-26T16:26:41.268400Z

Gather has a (m/or pattern _) inside it. It does a little bit more than that though to handle more advanced repeat cases.

ikrimael 2020-07-26T16:28:04.268600Z

i think i'm missing something bc i'm still seeing it as (gather (pred even?) == syntactic sugar for [(pred even?) ...] ?

ikrimael 2020-07-26T16:28:48.268800Z

except with the latter, that form also allows for dealing with maps

jimmy 2020-07-26T16:33:06.269Z

Imagine the sequence were [1 2 3]. The former expression would match. The latter would not because they are not all even numbers.

jimmy 2020-07-26T16:33:58.269200Z

Gather has nothing to do with maps. It is just matching on seqables using m/seqable

jimmy 2020-07-26T16:35:34.269400Z

Gather is almost syntatic sugar for (seqable (or pattern _) ...)

ikrimael 2020-07-26T17:12:05.269600Z

👍 ah right right. i keep blurring when things are exhaustive matches vs. not

ikrimael 2020-07-26T17:13:10.269800Z

i think i've hit [(pred even?) ...] => not doing what i just thought it did and then replacing it with scan and changing match to find or search until something works 😛

ikrimael 2020-07-26T17:14:21.270Z

caveat: i just recently discover m/map-of and m/submap-of which (correct me if i'm wrong) are the map equivalents for gather

jimmy 2020-07-26T17:14:24.270200Z

Yep. That is why I came up with gather. I found myself doing the same thing and realized most of the time I wanted a simple filter.

ikrimael 2020-07-26T17:15:59.270400Z

(btw, i've added all this info to the cookbook so it'll be in a PR in a week or so)

👍 2
ikrimael 2020-07-26T18:50:07.272Z

------------------ ah, also one more addition: i think it'd be great if there was a m/gather for maps e.g. if m/submap-of can be used with :as to capture the result of the submap filter

👍 1
noprompt 2020-07-26T20:13:12.272600Z

At the time map-of/`submap-of` was added, the inverse of this was suggested e.g. a way to capture the part of that map that didn’t match. I think both are useful and supportable. From my point of view this is yet more support for the idea that “folds”, as I have discussed them, are primitive and relevant i.e. these two problems are symptoms of the same underlying condition which is that we do not have a way to bind with reduction. Binding, in theory sense, is a sort of reduction operation that can fail. Logic variables bind values when they are unbound and fail when an attempt is made to bind them to a logically inequivalent value. Memory and mutable variables always bind. It makes sense [to me] that reduction be exposed to allow for binding to be rich and powerful.

👍 1
jimmy 2020-07-26T20:23:40.273400Z

> i find myself wanting to construct or extract a key out of a map alot with m/rerwrite but doing it inside of meander is frictive enough that i end up cheating and adding `(let [helperfn .....]) Got an example of this? Really curious to understand more.

ikrimael 2020-07-26T20:48:55.273600Z

sure (heads up, picked this bc its more convoluted than it needs to be but is a real snippet where I just "gave up in frustration" after wrestling with it for a couple hours)

ikrimael 2020-07-26T20:52:31.274500Z

really the important bits:

ikrimael 2020-07-26T20:54:59.274900Z

i have a feeling most of these issues are a symptom of lack of "gather" for maps (cx - the submap-ofthread) And I run into it more bc i'm using rewrite and thus using meander syntax to create vs. normal clojuree

ikrimael 2020-07-26T21:08:46.275100Z

----------------- oops, forgot to add what i wanted the code to do:

(xfm 
;; Operator Type Decl
{:in  {:fldname {:name ?name :ctype ?ctype :initval ?dlftval } ...} 
 :out {:fldname {:name ?name :ctype ?ctype :initval ?dlftval } ...}}
;; Map of Init Values
{:fldname ?fldinitval }
;; Result =>
{:prmin  {{:prmName ?name :prmType ?ctype :prmBind (or ?fldinitval ?dlftval :prmBindNone) }}
 :prmout {{:prmName ?name :prmType ?ctype :prmBind (or ?fldinitval ?dlftval :prmBindNone)}}} 
)
----- highlevel: it's usually around map construction on the right hand side e.g. - merge mapA mapB - update mapA's values from mapB - variations of "cartesian/relational" operations ie canonical sql join/filter/etc