meander

All things about https://github.com/noprompt/meander Need help and no one responded? Feel free to ping @U5K8NTHEZ
timothypratley 2020-03-16T15:35:21.258200Z

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

timothypratley 2020-03-16T15:37:52.259500Z

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.

timothypratley 2020-03-16T15:39:32.259700Z

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

timothypratley 2020-03-16T17:49:20.260100Z

(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
timothypratley 2020-03-17T15:29:13.270500Z

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

jimmy 2020-03-16T17:51:14.260200Z

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

timothypratley 2020-03-16T17:55:28.260500Z

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

timothypratley 2020-03-16T18:19:06.260700Z

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.

jimmy 2020-03-16T18:29:26.260900Z

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.

timothypratley 2020-03-16T20:27:47.263200Z

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

timothypratley 2020-03-16T20:44:22.263300Z

Also I wish it replaced all occurences 🙂

timothypratley 2020-03-16T20:49:02.263500Z

what does $* do ???? o_O

timothypratley 2020-03-16T21:00:44.263700Z

I claim $* is broken on epsilon

timothypratley 2020-03-16T21:14:10.264300Z

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

noprompt 2020-03-16T21:34:17.266600Z

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.

noprompt 2020-03-16T22:08:57.268400Z

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.

noprompt 2020-03-16T22:09:41.269300Z

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

noprompt 2020-03-16T22:18:28.269500Z

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

  ?x ?x)

noprompt 2020-03-16T22:18:57.269700Z

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

noprompt 2020-03-16T22:20:03.269900Z

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

noprompt 2020-03-16T22:20:16.270100Z

You could use top-down or bottom-up