Fork me on GitHub
#meander
<
2021-11-05
>
jjttjj19:11:21

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 Sless20:11:51

postwalk replace all the binding names deterministically then compare?

noprompt21:11:21

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

noprompt21:11:58

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.

noprompt21:11:12

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

noprompt21:11:32

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

noprompt21:11:49

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

noprompt21:11:04

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.

noprompt21:11:24

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

jjttjj21:11:26

Thanks both of you! This should get me started

noprompt23:11:59

Ping if you need more help, etc.

clojure-spin 1