Fork me on GitHub
#meander
<
2020-07-11
>
ikrimael00:07:35

@noprompt added a new example: Split stream based on filter and project https://github.com/noprompt/meander/blob/e562f563c42adf3763919dc7fb9cbab3b9c19b24/doc/cookbook.md#transform slowly getting the hang of things

ikrimael00:07:17

part i struggled with is applying an or predicate on a pattern that can match multiple times

ikrimael00:07:13

ie, i have an array of objects with a bitflag (possible values: EArgIn, EArgIn |EArgOut, EArgOut )

ikrimael00:07:47

i want to split them into an arg array of inputs and outputs but fields that had ArgIn|ArgOut would only show up in one of the arrays

noprompt00:07:08

Are you still struggling with this?

ikrimael00:07:14

heh, yeah. i finally gave up on it

ikrimael00:07:26

and marked "feature not supported" šŸ˜›

ikrimael00:07:56

(obvi jk, but i just let it be for now)

ikrimael00:07:32

(meta: i also have to say I absolutely love once I manage to get things in meander. everything is instantly grokkable days later)

noprompt00:07:37

Sure, sure. If you have a vanilla Clojure implementation and I might be able to supply a pattern for it.

noprompt00:07:19

Iā€™m really excited about the stuff youā€™re playing around with e.g. the C++ stuff because, really, this was the kind of space I wanted Meander to fit in to i.e. AST transforms, etc.

ikrimael00:07:36

yeah, it's literally the whole reason i'm using it

ikrimael00:07:48

i always hate how complicated term rewriting was for basic things

ikrimael00:07:59

re: code - sure, it's in the link. i tried to make it self contained so you can copy paste it

noprompt00:07:29

Gradually, Iā€™m realizing that what I want is essentially a DCG sort of thing but richer a bit different from whats on offer in Prolog and integrated with Clojure.

šŸ‘Œ 3
ikrimael00:07:14

each variant is a different tactic i tried (i kept it in the doc bc it helps shows the difference between {search , match} x {memory vars, logic vars}

noprompt00:07:22

I should have some more time over the weekend to review stuff, help with questions, etc.

noprompt00:07:50

Youā€™ve captured my attention. šŸ™‚

ikrimael00:07:50

and no rush; i basically just queue up everything and using that PR as a working draft

ikrimael00:07:21

my goal is once I finish writing this part of my dsl compiler in clojure to come back and edit the PR draft to final form

noprompt00:07:43

Sure. Just let me know what you need on that e.g. ā€œCan you fill in this blank or that blank?ā€ sort of thing.

noprompt00:07:23

For stuff youā€™re stuck on, a Clojure implementation can help. If I canā€™t map it, Iā€™ll be honest about that.

ikrimael00:07:21

would you prefer a straight clojure implementation or is higher level pseudocode better?

ikrimael00:07:13

ex: I wrote this as what i was trying to do and then tried to figure out how to get meander to map it

filter(
  (predA? x) => (projA x) :as !projAseq
  (predB? x) => (projB x) :as !projBseq
)

noprompt00:07:29

So I think that is

(m/or (m/pred predA? (m/app projA !projASeq))
      (m/pred predB? (m/app projB !projBSeq)))

noprompt00:07:02

Either is fine though, if Iā€™m confused Iā€™ll ask. šŸ™‚

šŸ‘ 3
ikrimael00:07:20

hmm, still can't get it to work

ikrimael00:07:41

Simplified snippet:

(def arglist [{:name :inBoneTrk    :argFlags #{:EArg-In}}
              {:name :inoutBoneTrk :argFlags #{:EArg-In :EArg-Out}}
              {:name :outBoneTrk   :argFlags #{:EArg-Out}}])
(m/match
 arglist
  [(m/or (m/pred #(contains? %1 :EArg-In) (m/app :name !projASeq))
         (m/pred #(contains? %1 :EArg-Out) (m/app :name !projBSeq)))
   ...]
  {:in-args !projASeq
   :out-args !projBSeq})

ikrimael00:07:44

Actual: Error: nonĀ exhaustiveĀ patternĀ match Expected:

{:in-args [:inBoneTrk :inoutBoneTrk]
 :out-args [:outBoneTrk :inoutBoneTrk]}

noprompt02:07:10

(let [arglist [{:name :inBoneTrk    :argFlags #{:EArg-In}}
               {:name :inoutBoneTrk :argFlags #{:EArg-In :EArg-Out}}
               {:name :outBoneTrk   :argFlags #{:EArg-Out}}]]
  (m/find arglist
    [(m/and (m/or {:argFlags #{:EArg-In} :name !projASeq} _)
            (m/or {:argFlags #{:EArg-Out} :name !projBSeq} _))
     ...]
    {:in-args !projASeq
     :out-args !projBSeq}))
;; =>
{:in-args [:inBoneTrk :inoutBoneTrk],
 :out-args [:inoutBoneTrk :outBoneTrk]}

noprompt02:07:02

You could use match instead of find in this case if you want ā€œblow upā€ semantics.

noprompt02:07:54

Alternatively

[(m/or {:argFlags #{:EArg-In :EArg-Out} :name (m/and !projASeq !projBSeq)}
           {:argFlags #{:EArg-In}, :name !projASeq}
           {:argFlags #{:EArg-Out}, :name !projBSeq})
     ...]
works.