meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
jimmy 2020-07-27T03:58:55.275400Z

Here are at least two things you can do to make this a tad bit more percise. First you can just use get directly, rather than binding a function.

(defn oprmbinds-mk [a_arg]
  (m/rewrite a_arg
    (:makeparmbinds ?valmap [{(m/or :name :fldname) (m/and !prmn1 !prmn2 !prmn3)
                              :ctype                {:ctuid !prmctuid}} ...])

    (m/map-of !prmn1  {:prmName  !prmn2
                       :prmCtuid !prmctuid
                       :prmBind  (m/app get ?valmap !prmn3 :prmbnd-none)})))
But technically, you don’t even need the get, maps are functions themselves.
(defn oprmbinds-mk [a_arg]
  (m/rewrite a_arg
    (:makeparmbinds ?valmap [{(m/or :name :fldname) (m/and !prmn1 !prmn2 !prmn3)
                              :ctype                {:ctuid !prmctuid}} ...])

    (m/map-of !prmn1  {:prmName  !prmn2
                       :prmCtuid !prmctuid
                       :prmBind  (m/app ?valmap !prmn3 :prmbnd-none)})))
I tried doing this with rewrites, and there is definitely a way, but I still ended up using the same little app trick. As for joins and stuff, those work fairly well with search/rewrites unless you want to do things like a default value if something doesn’t exist (like you are doing here). I played with trying to make it work with an explicit join and sadly came up a bit short. Through the m/app trick above would work, I was sad I couldn’t express it more directly.
(into {}
      (m/rewrites a_arg

        (:makeparmbinds {?param ?val} 
                        (m/scan {(m/or :name :fldname) ?param 
                                 :ctype {:ctuid ?prmctuid}}))
        [?param {:prmName ?param
                 :prmCtuid ?prmctuid
                 :prmBind ?val}]))

👍 1
dominicm 2020-07-27T09:58:19.276200Z

(into {} (m/search {:a nil :b 10 :c 20 :d nil}
                   {?k (m/some ?v)} {?k ?v})) ;; {:b 10, :c 20}
I feel like there's going to be a neater solution to this?

jimmy 2020-07-27T14:38:46.276300Z

(m/rewrite {:a nil :b 10 :c 20 :d nil}
  (m/gather [!k (m/some !v)])
  {& [[!k !v] ...]})
There's another way of doing it.

jimmy 2020-07-27T14:39:17.276500Z

Oh wait, forgot about map-of

(m/rewrite {:a nil :b 10 :c 20 :d nil}
  (m/gather [!k (m/some !v)])
  (m/map-of !k !v))

dominicm 2020-07-27T16:47:38.276700Z

ah, so gather is the proper way to collect the keys such that I can then map-of with them. I tried map-of a lot and got nowhere.

dominicm 2020-07-27T16:47:54.276900Z

I'm guessing gather actually iterates, whereas search is going pair-by-pair?

jimmy 2020-07-27T18:41:58.277100Z

Yeah in this case gather is equivalent to

(m/rewrite {:a nil :b 10 :c 20 :d nil}
  (m/seqable (m/or [!k (m/some !v)] _) ...)
  (m/map-of !k !v))