Message Sending
self
, however (the previous example is for instructional purposes only). You will be relying upon NewtonScript's lookup rules to determine which variable is being accessed and what its value is. Here are the lookup rules for finding a variable:1. Local variables or parameters are searched first.
2. If no local variable is found, slot names are searched using inheritance rules (covered in Chapter 4, Inheritance in NewtonScript). The lookup starts in the frame that is self
.
3. If no slot name variable is found, then global variables are searched.
If the variable still isn't found, a run-time error is generated.
The rules are slightly different when you are not searching for a variable but rather are assigning to one. The first three rules remain the same, but a fourth, very important rule has been added:
1. Local variables or parameters are again searched first.
2. Slot names are searched using inheritance rules. The lookup still starts with self
.
3. Global variables are again searched third.
4. If no variable has been found, a local variable is created with that name.
An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.
Last modified: 1 DEC 1996