Contents Previous Next Subchapters

Local Variables
Syntax local variable = value
See Also assignment , const

Description
Creates a new variable that has file scope and assigns it a value.

Tutorial
Local variables are limited in scope to the files in which they are defined. Suppose the file TEMP.OMS contains the commands
     local y = 7
     print y
and you enter the commands
     y = 8
     include TEMP.OMS
O-Matrix will respond
     7
because the value of y within the file TEMP.OMS is 7. If you continue by entering
     print y
O-Matrix will respond
     8


If a function is defined after a local variable, the local variable is visible within the function. This is different variables that are not defined as local because they require a global statement to make them visible within a function.

If the file TEMP.OMS contains
     clear
     local z = 10
     function f() begin
          print z
     end
     f
and you enter
     include TEMP.OMS
O-Matrix will respond
     10

Reference
A local statement can only appear in a file (not at the command line) and it cannot be inside of any function.