meander

2021-11-05T19:10:21.027800Z

Is there a way to get an "identity" of a quoted meander query such that two queries can be compared for equality and will be equal even if the binding names used are different?

Ben Sless 2021-11-05T20:55:51.027900Z

postwalk replace all the binding names deterministically then compare?

noprompt 2021-11-05T21:07:21.028100Z

Great question. Ben's reply is good here. You could use something like this to make a name mapping: https://github.com/noprompt/meander/blob/epsilon/src/meander/syntax/epsilon.cljc#L1636-L1646

noprompt 2021-11-05T21:11:58.028400Z

This could get you to a place where you can tell if two forms are representationally equivalent (almost) but not semantically equivalent. So terms like

[?a [?b 1 ?a]]
[?1 [?2 1 ?1]]
could be found to be equivalent via the method of constructing the rename map deterministically and then applying it.

noprompt 2021-11-05T21:14:12.028700Z

I think this will also work for persistent array maps but, of course, on larger maps a simple = check may not work.

noprompt 2021-11-05T21:16:32.029Z

For fewer traversals, you could try comparing the subnodes for each of the terms iteratively, building the rename map as you go.

noprompt 2021-11-05T21:25:49.030100Z

If you're interested in this problem, I've actually wanted a unifier for Meander terms for a little while. It'd be useful.

noprompt 2021-11-05T21:28:04.030300Z

Because this is very much like unification, we want to see if one term is essentially equivalent to another. This has implications for things like cata where we could use that information.

noprompt 2021-11-05T21:32:24.030500Z

(m/rewrite x
  (foo (m/cata [?a ?b]))
  {:type "foo", :a ?a, :b ?b}
  
  ?x
  {:type "unknown", :form ?x})
This is an example where that information could be used to demonstrate to a user the cata form could never succeed.

2021-11-05T21:43:26.030700Z

Thanks both of you! This should get me started

noprompt 2021-11-05T23:10:49.030900Z

Awesome!

noprompt 2021-11-05T23:10:59.031100Z

Ping if you need more help, etc.

1