Combining Proto and Parent Inheritance

Accessing Slots

There are also a number of different ways to test whether a slot exists. As you can see in TABLE 4.1, different lookup occurs depending upon whether you use variableName or frame.variableName to access a slot. Most importantly, notice that frame. syntax (for example, foo.slotA) does not use parent inheritance.
Different ways to access slots.
SyntaxExampleUses Proto InheritanceUses Parent Inheritance
slotslotAXX
frame.slotfoo.slotAX 
frame.(pathExpr)foo.('slotA)X 
GetVariable(frame, symbol)GetVariable(foo, 'slotA)XX
GetSlot(frame, symbol)GetSlot(foo, 'slotA)  

An unexpected effect of this scheme of inheritance occurs when you wish to explicitly use the self variable in lookup. There is a definite difference between accessing a variable using slot and self.slot. As you can see in TABLE 4.2, an explicit use of self. disables parent inheritance.
How the use of self affects slot access.
SyntaxExampleUses Proto InheritanceUses Parent Inheritance
slotslotAXX
frame.slotself.slotAX 
frame.(pathExpr)self.('slotA)X 
GetVariable(frame, symbol)GetVariable(self, 'slotA)XX
GetSlot(frame, symbol)GetSlot(self, 'slotA)  

This is the case because self.slot is just a case of using frame.slot. Therefore, you should only use self. when you are certain you don't want parent inheritance ("Using self in a Method" covers this issue in more detail).


An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996