This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-05-02
Channels
- # announcements (7)
- # aws (3)
- # babashka (132)
- # beginners (38)
- # calva (3)
- # chlorine-clover (6)
- # clara (1)
- # clj-kondo (20)
- # cljs-dev (24)
- # cljsrn (9)
- # clojure (76)
- # clojure-dev (1)
- # clojure-germany (4)
- # clojure-india (2)
- # clojure-uk (24)
- # clojurescript (15)
- # conf-proposals (1)
- # conjure (114)
- # cursive (3)
- # fulcro (63)
- # graalvm (1)
- # helix (2)
- # joker (10)
- # juxt (1)
- # local-first-clojure (2)
- # meander (9)
- # off-topic (97)
- # rdf (4)
- # re-frame (7)
- # reagent (16)
- # reitit (1)
- # rum (9)
- # shadow-cljs (48)
- # spacemacs (3)
- # tools-deps (3)
- # vim (30)
- # xtdb (10)
Hello! I'm playing with meander and am really impressed by it. I was wondering what would be the meander way to parse a regular clojure fn or
defn form ? (i'm struggling a bit in order to express elements that could be there or not (like the name of the lambda or the metadata map in the `defn for instance). thank you in advance.
Sorry for the late reply. I will hopefully be able to answer this thoroughly today. It is actually something that comes up quite often so, I plan on adding some examples to the cookbook. Optionality is a little difficult just because it is context sensitive. The easiest (but often times not scalable) answer is to make multiple patterns that match with or with out it. Like I said, I should have an example later today.
@U0A7SU3FS Here is one way: https://github.com/timothypratley/justice/blob/master/src/justice/defn.cljc
FWIW If you compare it with the “spec driven approach” linked in the comment I think Meander is way more expressive 🙂
note that the way I emulated “optional” was to use a memory variable constrained to contain 1 or 0 elements
I wish Meander had a built in operator for optional (hint hint @U06MDAPTP)
@U06S1EJPL The memory variable trick works too. I didn’t use it in the example. 🙂
I tried to hack on in one time. But the compiler depends on the length of a pattern quite often to be able to do things intelligently. I found myself running into trouble because of that.
Also as a side topic; you can use tools analyzer to parse/emit normalized versions then match with meander to remove most optionality (happy to share examples on that too if interesting).