Fork me on GitHub
#meander
<
2020-07-16
>
ikrimael00:07:19

@noprompt quick question (sorry, no complete snippet, rushed at the moment); is it possible to destructure while "capturing" something

ikrimael00:07:31

ex:

[ {:op :ophirUseOpnDataLit :as !opdataLits} ...]

jimmy00:07:34

What you wrote there does work. Not sure what you are looking for.

ikrimael00:07:25

oops, @jimmy sorry pasted too soon

ikrimael00:07:29

the array passed in is

[{:op :ophirUseOpnDataLit,
   :name :datalit_smoothArgs,
   :ctypeUid {:op :ophirCuid, :cuidstr :SmoothingChop_PrmBlk_t},
   :fldvalmap
   {:chSmplRate {:op :ophirConst, :ctypeUid :SmplRate_t, :val 1},
    :chStartSmplNum {:op :ophirConst, :ctypeUid :SmplIdx_t, :val 1}}}
  {:op :ophirUseOpnode,
   :name :loPass,
   :opdefUid {:op :ophirOpuid, :opuidstr :smootherchop},
   :oprmblkbnds
   {:op :ophirOprmblkBinds,
    :oprmbnds
    [{:op :ophirOprmbind,
      :prmname :smoothArgs,
      :prmbind {:op :ophirOprmPath, :pathstr "opgrph:./opnodes/opgrphdata/smoothArgs1"}}
     {:op :ophirOprmbind, :prmname :chIn, :prmbind {:op :ophirOprmPath, :pathstr "opgrph:./oprms/inBoneTrk"}}]}}
  {:op :ophirUseOpnode,
   :name :hiPass,
   :opdefUid {:op :ophirOpuid, :opuidstr :smootherchop},
   :oprmblkbnds
   {:op :ophirOprmblkBinds,
    :oprmbnds
    [{:op :ophirOprmbind, :prmname :smoothArgs, :prmbind {:op :ophirOprmPath, :pathstr "opgrph:/loPass/@smoothArgs"}}
     {:op :ophirOprmbind, :prmname :chIn, :prmbind {:op :ophirOprmPath, :pathstr "opgrph:/loPass/@chOut"}}]}}]

jimmy00:07:01

And you want to get only the ones with a certain op?

ikrimael00:07:15

i want to extract out {:name :ctypeUid} from the meander filter (but only if it's :op == :ophirUseOpnDataLit)

jimmy00:07:40

You can use m/gather.

ikrimael00:07:51

i can't figure out how to "crack open" the inner parts through a destructure while keeping a memory variable

jimmy00:07:58

It is like filter.

ikrimael00:07:04

ah brilliant; let me look that up

ikrimael00:07:44

thnx! will come back tonight and update the sample PR with it or ask questions if i stumble

ikrimael00:07:04

(trying to check something in in <1hr šŸ¤“ )

jimmy00:07:11

Sounds good.

JAtkins02:07:25

I think I'm being stupid here, but I'm not sure how... I have seen this error several times now:

Execution error at scratch.overcast-xml/eval19536$fn$fn (overcast_xml.clj:29).
Can't remove struct key
I've solved it a few times now, but I'm still not sure what the causal pattern it is. Here is my most recent example:
(m/search file ; some xml, can provide a subset if needed
    (m/$ {:attrs   {:xmlUrl (m/some ?rss-feed)}
          :content (m/scan {:tag   :outline
                            :attrs !attrs})})
    {:rss ?rss-feed  :attrs !attrs})

noprompt04:07:36

@jatkin There might be something up how Meander is interacting with the XML library. Do you have, perhaps, a deps.edn and a minimal example that triggers this problem? Iā€™m happy to have a look at it.

JAtkins04:07:39

Looks like the type is clojure.lang.PersistentStructMap, which maybe doesn't allow dissocing... Which would make sense... It's just clojure.xml

JAtkins04:07:21

Yup, that's it... Not meander šŸ™‚ Thanks for bringing that up, would never have thought of that!

šŸ‘ 3
JAtkins20:07:28

So, another possible dumb question: can I unroll results? e.g. I have a match with a capture and a memory variable. can I unroll the result with the single capture reused while all the memory vars are used? My usage rn:

(m/search xml-cleared-structs
    (m/$ {:attrs   {:xmlUrl (m/some ?rss-feed)}
          :content (m/scan {:tag   :outline
                            :attrs {:progress (m/some !progress)
                                    :title    (m/some !title)}}
                     )})
    {:rss ?rss-feed :progresses !progress :titles !title})

;; => 

({:rss "",
  :progresses ["3642"],
  :titles ["Why Functional Programming Matters"]}
 {:rss "",
  :progresses ["2200" "3190"],
  :titles ["My response to Out of the Tar Pit" "Another Title"]})

noprompt22:07:05

Is the value on the right of the => the expected?

JAtkins22:07:34

The actual

JAtkins22:07:37

I got a bit closer with this:

(m/search xml-cleared-structs
    (m/$ {:attrs   {:xmlUrl (m/some ?rss-feed)}
          :content [_ ... {:tag   :outline
                           :attrs {:progress (m/some ?progress)
                                   :title    (m/some ?title)}}
                    ]})
    {:rss ?rss-feed :progresses ?progress :titles ?title})
But it only matches the last element in the :content vector

JAtkins22:07:05

Haven't figured out how to put the zero or more in the right place for this to match everything correctly