meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
william 2021-04-18T15:31:21.124800Z

Hey, I have a question on some code I wrote to do parsing for an advent of code problem:

(meander/defsyntax keywordize [a b]
  `(meander/app #(keyword (str %1 "-" %2)) ~a ~b))

(meander/defsyntax to-map [a]
  `(meander/app (partial apply hash-map) ~a))

(meander/defsyntax parse-int [str]
  `(meander/app #(Integer/parseInt %) ~str))

(defn parse-description [description]
  (meander/rewrite
   (str/split description #" ")
   [?adj ?col _ "contain" . !ns !adjs !cols _ ...]
   {(keywordize ?adj ?col) (to-map [(keywordize !adjs !cols) (parse-int !ns) ...])}))

(def example
  "plaid magenta bags contain 2 clear lavender bags, 3 clear teal bags, 4 vibrant gold bags.")

(parse-description example)
;; {:plaid-magenta {:clear-lavender 2, :vibrant-gold 4, :clear-teal 3}}
The solution is beautifully concise, but there's a bit more verbosity in the third argument of meander/rewrite because I want to slightly transform the output (unifying two memory variables in a keyboard, get the parse of another, etc. This brings me to define all those defsyntax rule. Is there a way to accomplish this with less ceremony and more clarity? (ps meander is beautiful)

william 2021-04-18T16:12:45.125Z

reading the code, I discovered meander/map-of with which I can slightly clean the code and get rid of my to-map. The other two definitions still stand though, I'd really like to at least turn them in inline constructs

william 2021-04-18T16:23:52.125200Z

Ok, this is the version I'm happy with ❤️

jimmy 2021-04-18T18:09:50.125600Z

Looks pretty great to me! Glad you were able to figure things out