meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
Lucy Wang 2020-09-28T14:10:02.166400Z

the beauty of extracting JIRA api response with meander, really ❤️ it

(defn format-issues [issues]
  (me/search issues
    (me/scan {:fields {:summary ?summary
                       :assignee {:displayName ?assignee}
                       :status {:name ?status}}})
    {:summary ?summary
     :assignee ?assignee
     :status ?status}))

❤️ 1
🚀 1
Lucy Wang 2020-09-28T14:54:58.166900Z

and now I have too handle some nils ...

(defn format-issues [issues]
  (me/search issues
    (me/scan {:fields {:summary ?summary
                       :assignee (me/or (me/let [?assignee nil]
                                          nil)
                                        {:displayName ?assignee})
                       :status {:name ?status}}})
    {:summary ?summary
     :assignee ?assignee
     :status ?status}))

Lucy Wang 2020-09-28T15:05:19.167500Z

time for some defsyntax!

(defn logic-variable? [x]
  (and (symbol? x)
       (str/starts-with? (name x) "?")))

;; (logic-variable? '?x)
;; => true

(defn extract-logic-variables [m]
  (sp/select (sp/walker logic-variable?) m))

;; (extract-logic-variables '{:a ?a :b ?b :c "?c" :d :?d})
;; => [?a ?b]

(me/defsyntax maybe-map
  [m]
  (if (me/match-syntax? &env)
    `(me/or
       (me/let ~(->
                 (extract-logic-variables m)
                 (interleave (repeat nil))
                 vec)
         nil)
       ~m)
    &form))

(defn format-issues [issues]
  (me/search issues
    (me/scan {:fields {:summary ?summary
                       :assignee (maybe-map {:displayName ?assignee})
                       :status {:name ?status}}})
    {:summary ?summary
     :assignee ?assignee
     :status ?status}))

jimmy 2020-09-28T15:33:00.167800Z

I know you got a nice little defsyntax for this. Just wanted to point out this little and idiom.

(defn format-issues [issues]
  (m/search issues
    (m/scan {:fields {:summary ?summary
                      :assignee (m/or (m/and nil ?assignee)
                                      {:displayName ?assignee})
                      :status {:name ?status}}})
             {:summary ?summary
              :assignee ?assignee
              :status ?status}))

unbalanced 2020-09-28T15:49:03.168500Z

I'm curious, has anyone put any thought into a symbolic syntax for Meanderlang?

unbalanced 2020-09-28T15:51:31.169200Z

The two closest cousins I can find are Dyalog APL and the mathematical field of topology

unbalanced 2020-09-28T15:52:41.169800Z

Or maybe those things like me/scan macroexpand into a more verbose data literal syntax?

noprompt 2020-09-28T21:13:38.169900Z

@goomba Yes. me/scan essentially expands to

(m/seqable _ … p1 ,,, pN . _ ...)
which expands to
(m/pred seqable? (m/app seq (_ ... p1 ,,, pN . _ ...))

noprompt 2020-09-28T21:15:04.170100Z

Originally, me/scan expanded to

(m/or (_ ... p1 ,,, pN . _ ...)
      [_ ... p1 ,,, pN . _ ...))
but this expansion could result in large code explosions which is a problem which still needs to be addressed.