Incoherency of pretty-printing fixed
Created by: MikaelMayer
I removed the intermediate conversion to a Map[Expr, Expr]
because the printing is not consistent with the tree definition, and thus would result in a different parsing if we had parsing, and hence to a bug. Look the following example:
val tr = Map("A" -> "B", "A" -> "C", * -> "...")
tr("hello")
From the semantics of Map, it's clear that the second A
overrides the first; therefore the output is "C"
.
However, if after re-printing and parsing, the order is changed:
val tr = Map("A" -> "C", "A" -> "B", * -> "...")
tr("hello")
the output changes to "B". This can happen because the .toMap.toSeq
takes hashcodes on expressions to rely on sorting.
Another example is when I define translation maps, I don't want to have the order to change because they might have be groupped semantically. That is, the same way when we do program repair, we don't change the order of variables at first.