Inheritance in NewtonScript

Parent Inheritance

Now it is time to cover the second form of inheritance in NewtonScript: parent inheritance. An object can have two inheritance slots, one for its proto and one for its parent. The _parent slot points to another frame from which the object inherits and is used only in these two instances:

Let us look at this first instance by examining the following code:

	copyCat.unknownSlot := "Grin";
	someSlot := 72;
Proto inheritance is used both for looking up a variable and for explicitly accessing a slot from a frame. Parent inheritance is not used when explicitly accessing a slot from a frame.

When you use slot access (like copyCat.unknownSlot), then only copyCat and its proto chain are searched for unknownSlot.

On the other hand, if you do not use dot syntax (like someSlot := 72), then lookup occurs in the following order:

The other time that parent inheritance comes into play is when you send a message to a method. So, for instance:

copyCat:SomeMessage(felix)
will search the parent chain of copyCat (as well as each ancestor's proto chain) to find the SomeMessage method.


Note:About now, some of you might be wondering why NewtonScript was designed to treat dot "." lookup (frame.slot) differently from colon ":" lookup (frame:Method()). Remember, ":" follows the parent and proto chains, while "." follows only the proto chain. The simplest answer to this question is "just because it does." You should simply realize that there is no grand scheme in which this distinction is a critical component, so don't think you are missing something here.


Now that you have that brief introduction to parent inheritance, let us look at how proto and parent inheritance combine with each other in NewtonScript.


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

Last modified: 1 DEC 1996