Why indexNum instead of nodeNum?

I'm posting this for my own reference. A few weeks from now I won't remember why.

I've been considering this question: "Why not use the nodeNum in the parent/firstChild/nextSibling/prevSibling fields?"

Well, in very general terms, consider that any Object may reference any other Object. A Block object might reference a Node object. A Symbol object might reference a Node object. A Scope object my reference a Block object. There has to be an extremely general purpose mechanism for any one Object to reference any other Object. That's what the indexNum and index->offset gives us.

I *could* make those four fields be the nodeNum rather than the indexNum, but then what about other Objects (like Blocks and Symbols) that reference JPNode objects? That's something I cannot do... I cannot go changing every Object.field which is a reference to a JPNode object.

So... we need to use indexNum. Do we use it *instead of* nodeNum? No, I don't think so, because nodeNum is easier to understand, and the fact that nodeNum has an easy to follow sequence down through the tree, it is useful and nice to work with.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Since you have added Nodemum

Since you have added Nodemum as a field to the JPNode class, there is no issue at all. FYI, when the nodes are initialised (with or without the node objects) the parent/firstChild/nextSibling/prevSibling fields are changed to nodenumbers as it makes it a lot easier to manipulate the TTnode table within the API. This means that all references to nodes are converted to the appropriate nodenumber before the TTnode table is available to anyone.