Creating Slots

Multilevel Slot Creation

A subtle, but important, aspect of easy frame and slot creation becomes evident when you assign to a slot several levels deep. Here is the rule:

Consider the following, slightly foolish, example. In the first statement, you create a frame x with one slot, a. Next, you assign an integer value of 5 to a slot that is deeply nested within x:

x := {a: 1};
x.b.c.d.e.f := 5;
Perhaps a cascading result is not what you expected, but it is what you get. The second assignment statement actually creates four frames just so it can carry out the assignment. FIGURE 3.2 shows the frames in memory after the code executes.

FIGURE 3.2 : After executing x.b.c.d.e.f := 5.


When NewtonScript sees a multilevel slot access on the left-hand side of an assignment statement, it creates those frames that didn't already exist. Each of these newly created frames has a single slot in it.


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

Last modified: 1 DEC 1996