Fundamentals of NewtonScript

Types

Values in NewtonScript are stored as 32-bit references (two of those bits are used for meta information). There are two types of references:

Immediate
Those values that can completely fit in 30 bits: integers, characters, and booleans.

Nonimmediate
Those values that are too big for 30 bits: strings, symbols, real numbers, frames, arrays, and binary objects (such as bitmaps or functions).

When you copy a value with an assignment statement, the 32-bit reference is copied. If the value fits in the reference (immediate), then the value is copied. If the value is larger than the 32-bit reference (nonimmediate), then only a pointer to the value is copied. Likewise, when you pass a parameter, the 32-bit reference is passed. Consider the following assignments:

a := [1, 2, 3];
b := a;
The values of a and b are the same 32-bit reference--they are both pointing at the same array (see FIGURE 3.3).

FIGURE 3.3 : Two variables pointing at the same array.


If you were to change one of the elements using the a array, the array element is also changed for b:

a[0] := 5;
Print(b);
[5, 2, 3]
What Types Can Be Modified
Clone/DeepClone

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

Last modified: 1 DEC 1996