Comparing nlists containing nodes


I've got two lists of nodes. The contained nodes are copies of each other. Thus, when "logging" the content of the lists it looks like:

... nlist1 contains: [node1, node2]
... nlist2 contains: [node1, node2]

I want to use the lists like:

if(nlist1 != nlist2) {...}

!= seems not to be the proper operator for doing this. Is there a special operator or am I required to iterate over the lists and compare single elements?




1 comment

Hi Henning,

you would have to define what it means that two nodes are "equal". 

If you have a node A and a node A*, which is a copy of A, they cannot be referentially equal, since they are two different objects. If I understand you correctly, you want an operator or operation that takes two nlist objects and returns true if and only if the two lists contain 

  • the exact same number of nodes
  • for each node in the first nlist there is a node in the second list (at the same index?) that has the "same value"

Now, comparing two MPS nodes is quite tricky and again you would have to define what "equality" means to you, since a node A can have children and references to other nodes.

There are some ways that might solve your specific issue. 

  • there is the "matches" keyword (EqualsStructurallyExpression) in the smodel language that you might want to use to compare your nodes; you would have to compare each element of your lists one by one; potential pitfals are NodeAttributes / PropertyAttributes, that you might want to ignore since they might not be part of your definition of equality
  • You can use the MatchingUtil type directly ("matches" keyword uses this util as well) to use matchModifiers and to decide whether or not to match attributes
  • there is also something in mbeddr (maybe it is part of mps-extensions by now), called the MPSNodeComparator, but as I discuss here, it might struggle with cyclic dependencies:!searchin/mbeddr-discuss/rwalter%7Csort:date/mbeddr-discuss/I1BYHwrYrDs/hJCvKLLZBwAJ

I've implemented a custom node navigation API to handle node navigation in general, and use it to handle different "equality requirements" in my languages. Unfortunatelly, I cannot make it open source yet, but maybe I'll find some time to do this soon.




Please sign in to leave a comment.