Fork me on GitHub

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?


Great question. Ben's reply is good here. You could use something like this to make a name mapping:


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.


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


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


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


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.


(m/rewrite x
  (foo (m/cata [?a ?b]))
  {:type "foo", :a ?a, :b ?b}
  {: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.


Thanks both of you! This should get me started


Ping if you need more help, etc.

clojure-spin 1