Fork me on GitHub
#meander
<
2020-03-16
>
timothypratley15:03:21

(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?

timothypratley15:03:52

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.

timothypratley15:03:32

^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.

jimmy17:03:14

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

timothypratley18:03:06

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.

timothypratley17:03:20

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

(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))])

👍 1
timothypratley17:03:28

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..

jimmy18: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.

noprompt21:03:17

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.

timothypratley15:03:13

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

timothypratley20:03:47

(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)

timothypratley20:03:22

Also I wish it replaced all occurences 🙂

timothypratley20:03:02

what does $* do ???? o_O

timothypratley21:03:44

I claim $* is broken on epsilon

timothypratley21:03:10

(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..

noprompt22:03:28

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

  ?x ?x)

noprompt22:03:57

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

noprompt22:03:03

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

noprompt22:03:16

You could use top-down or bottom-up

timothypratley00:03:40

(def p
  (s/top-down
    (s/match
      (m/pred string? ?s) (keyword ?s)
      ?x ?x)))

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

noprompt22:03:57

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.

noprompt22:03:41

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