Method Resolution Order in Io

Prunedtree asked the Io channel at Freenode: “How does Io avoid diamonds and cycling when finding methods in protos? Is there code to resolve loops?” Here is the answer.

*Jer*: If anything, io’s protos is more of a graph an unordered, unrestrained graph of some sort which can have edges connecting wherever.

*prunedtree*: jer : what about if A has proto B and B has C and C has B ? :p

*jer*: prunedtree, what about it?
It won’t look up in a proto twice in the same lookup sequence. That is, the diamond problem doesn’t happen in Io.
If a lookup fails in A, it’ll go to B, if it fails in B, it’ll go to C, if it fails in C, it’ll raise an exception
assuming that those are the only protos in play.

*prunedtree*: How does it avoid diamonds? Flags?

*jer*: I forget the proper term for it, but we make sure we don’t look up in the same object twice within the same lookup sequence. where “lookup sequence” is defined as having a lookup fail someplace before, and not resolved yet.

*prunedtree*: So it is setting a flag.

*jer*: Right, which is packed into the IoObject structure. Sets a bit field on it.

*prunedtree*: Yep. Colors the graph to avoid cycles.

*jer*: nod

*prunedtree*: That’s reassuring ;)

[tags]Io[/tags]

Published by Olle Jonsson

Human. Wears glasses and often a smile.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.