Fork me on GitHub

(m/match 1 ^String ?s ?s)
^^ I’d like this to not match… i.e. I’d like Meander to treat type hints as special predicates… thoughts?


The motivation being that I have a lot of (m/pred string? ?s) and I’d argue that it obscures the structure of what I’m matching, where as ^String doesn’t change the structure.


^String being the way to type hint in Clojure makes it somewhat intuitive that if I type hint a pattern, I’d like it to conform to the type.

Jimmy Miller17:03:14

Why meta over just a string operator? (string ?d)


FWIW I get a little confused whenever I see (anything);; is that going to match a list or a thing? Well, it depends on what anything is naturally 🙂 Conversely I like when I can write [] or {} and know that it will only match a vector or map. So type hints feel like a more familiar way to say this thing is an X(m/pred string? ?s) is in my view not any worse than (string ?s) so given those options, I’d probably stick with m/pred just because it’s more obvious when reading.


(defn chain [x [c & chains]]
  (if c
    (recur (list '. x c) chains)

(defn chain [xs]
  (m/rewrite xs
    [?x ()] ?x
    [?x ((!chain ...) & ?more-chains)]
    (m/cata [('. ?x . !chain ...) ?more-chains])))

(chain ['(new List) '((push_back 1)
                      (push_back 2)
                      (push_back 3))])

👍 4

1. It seems wierd to me that I can use the meander version of rewrite with m/cata but not the strategy version. There is probably a good reason though. 2. m/cata seems like the dual of m/with 3. Is the meander version better? I think so but am having trouble justifying it..

Jimmy Miller18:03:26

I can't really speak to why strategies doesn't have cata. I will say that we are hoping with zeta that strategies will not need to be separate and will not be function combinator based. Not 100% sure what that looks like yet though.


Strategy rewrite could have cata. The only thing that doesn’t have cata is rewrites because the current state of the compiler on epsilon would require some heavy rework to make of feasible.


roger roger; was just curious, not requesting 🙂 thanks for clarifying.


(m/rewrite [1 ["a" 2] "b" 3 "c"]
  (m/$ ?replace (m/pred string? !s))
  ~(?replace (map keyword !s)))
^^ Doesn’t work (perhaps unsurprisingly) => [1 [(:a) 2] "b" 3 "c"] What I’m trying to do is convert all the strings to keywords… Well what I’m really trying to do is more complicated than that but this is a minimal example 🙂 TLDR it would be awesome if $ could substitute transformations (not just values)


Also I wish it replaced all occurences 🙂


what does $* do ???? o_O


I claim $* is broken on epsilon


(m/rewrite [1 ["a" 2] "b" 3 "c"]
  (m/$ ?replace (m/pred string? ?s))
  (m/cata ~(?replace (keyword ?s)))
  ?x ?x)
^^ This works but is kinda gross because it will restart the tree walk over from scratch each time..


(me/rewrite [1 ["a" 2] "b" 3 "c"]
  (me/$ ?replace (me/pred string? ?s))
  (me/cata (me/$ ?replace (me/keyword nil ?s)))

  ?x ?x)


But, yes, you are right it is gross that it has to rewalk.


This is something I want to address in the near feature with a tree thing for describing these kinds of things.


You could use top-down or bottom-up


(def p
      (m/pred string? ?s) (keyword ?s)
      ?x ?x)))

(p [1 ["a" 2] "b" 3 "c"])
=> [1 [:a 2] :b 3 :c]


Hey folks I’m going to pull the explicit dependency on ClojureScript out of the project. @kenny had made a patch for this and then I merged it but walked back the ClojureScript dependency.


So now I’m going to remove the dependency, put in some conditional logic to load the required CLJS stuff.