LOCAL

Synopsis
LOCAL varname
LOCAL varnamelist
(LOCAL varname1 varname2 ...)
Description

Creates variables that are local to the currently running procedure. LOCAL accepts as input one or more words, or a list of words. A local variable is created for each of these words, with that word as its name. Logo variables follow dynamic scope rules; a variable that is local to a procedure is available to any sub procedure invoked by that procedure and may shadow a global variable by the same name. The variables created by LOCAL have no initial value; they must be assigned a value (for example, with MAKE) before the procedure attempts to read their value.

Local variables have a strange interaction with event-driven callbacks, such as the ones scheduled with SETTIMER or KEYBOARDON. When an event-driven callback is run, it interrupts whatever procedure is running (if any). Whatever variables are local to the procedure that got interrupted are available to the event-driven callback as if it were a sub procedure. Therefore, when a procedure that schedules an event-driven callback is interrupted by that event, then all of the variables which are local to that procedure are available to the event-driven callback. However, if the event-driven callback is run after the procedure which scheduled it exits, then variables where were local to that procedure are not available to the event-driven callback.

Example
TO FOO
  MAKE "bar 1
  PRINT :bar
END

FOO
1

SHOW :bar
1

TO ABC
  LOCAL "xyz
  MAKE "xyz 1
  PRINT :xyz
END

ABC
1

SHOW :xyz
xyz has no value

SourceForge.net Logo