Exceptions

Named Variables and Parameters


GetNamedVar(stacklevel, 'variablename)


To display a local variable, parameter, or other named variable from one of the functions in the stack trace, use the global function GetLocalFromStack. The function takes two parameters. The first is the stack level. The second parameter is the symbol of the variable whose value you want. Thus, to get the value of local1InB from the MethodB function in the example stack trace, you would use:

GetNamedVar(2, 'local1InB);

#294      165

GetAllNamedVars(stacklevel)


This routine prints all the variables which are referenced by name in the routine at the specified stack level. For example:

GetAllNamedVars(1)

#4417AF9  {param1InC: 3, 
           param2InC: 25, 
           local1InC: "abc", 
           local2InC: "bar", 
           text: "Button", 
           MethodD: <function, 0 arg(s) #6006F71D>}

SetNamedVar(stacklevel, 'variablename, newValue)


This routine actually lets you set a new value for named variables at any level on the stack. For example:

SetNamedVar(2, 'local1InB, 52)
#D0       52

GetAllNamedVars(2)
#4418031  {param1InB: "hello", 
           local1InB: 52, 
           MethodC: <function, 2 arg(s) #6006F565>}

GetPathToSlot(aFrame, 'slotname)


This routine returns the path where slotname is found in aFrame. Like GetVariable, it uses proto and parent inheritance, but instead of returning the value of the slot, it returns the path to where the slot is found. For example:

w := {a: 1, b: 2};
x := {_proto: w, a: 3};
y := {c: 6};
z := {_proto: y, _parent: x, d: 5};

GetPathToSlot(z, 'a);
#441CEA1  _parent.a

GetPathToSlot(z, 'b);
#441CF69  _parent._proto.b

GetPathToSlot(z, 'c);
#441D075  _proto.c

GetPathToSlot(z, 'd);
#441D13D  d

GetPathToSlot(z, 'e);
#441D24D 

GetPathWhereSet(aFrame, 'slotname)


This routine returns the path where slotname would be assigned in aFrame. Like SetVariable, it uses proto and parent inheritance, but instead of assigning to slotname, it returns the path to where the slot would be assigned. For example:

w := {a: 1, b: 2};
x := {_proto: w, a: 3};
y := {c: 6};
z := {_proto: y, _parent: x, d: 5};

GetPathWhereSet(z, 'a);
#441D30D  _parent.a

GetPathWhereSet(z, 'b);
#44145D1  _parent.b
GetPathWhereSet(z, 'c);
#44197C1  c

GetPathWhereSet(z, 'd);
#440FDED  d

GetPathWhereSet(z, 'e);
#440FEB1 

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

Last modified: 1 DEC 1996