home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Utilities / Calc / help / variable < prev   
Encoding:
Text File  |  1992-02-24  |  2.4 KB  |  54 lines  |  [TEXT/????]

  1. Variable declarations
  2.  
  3.     Variables can be declared as either being global or local.
  4.     Global variables are visible to all functions and on the command
  5.     line.  Local variables are visible only within a single function or
  6.     command sequence.  When the function or command sequence returns,
  7.     the local variables are deleted.
  8.  
  9.     To declare one or more variables, the 'local' or 'global' keywords
  10.     are used, followed by the desired list of variable names, separated
  11.     by commas.  The definition is terminated with a semicolon.  Examples
  12.     of declarations are:
  13.  
  14.         local    x, y, z;
  15.         global    fred;
  16.         local    foo, bar;
  17.  
  18.     Within function declarations, all variables must be defined.
  19.     But on the top level command line, assignments automatically define
  20.     global variables as needed.  For example, on the top level command
  21.     line, the following defines the global variable x if it had not
  22.     already been defined:
  23.  
  24.         x = 7
  25.  
  26.     Variables have no fixed type, thus there is no need or way to
  27.     specify the types of variables as they are defined.  Instead, the
  28.     types of variables change as they are assigned to or are specified
  29.     in special statements such as 'mat' and 'obj'.  When a variable is
  30.     first defined using 'local' or 'global', it has the null type.
  31.  
  32.     If a procedure defines a local variable name which matches a
  33.     global variable name, or has a parameter name which matches a
  34.     global variable name, then the local variable or parameter takes
  35.     precedence within that procedure, and the global variable is not
  36.     directly accessible.
  37.  
  38.     There are no pointers in the calculator language, thus all
  39.     arguments to user-defined functions are normally passed by value.
  40.     This is true even for matrices, strings, and lists.  In order
  41.     to circumvent this, the '&' operator is allowed before a variable
  42.     when it is an argument to a function.  When this is done, the
  43.     address of the variable is passed to the function instead of its
  44.     value.  This is true no matter what the type of the variable is.
  45.     This allows for fast calls of functions when the passed variable
  46.     is huge (such as a large array).  However, the passed variable can
  47.     then be changed by the function if the parameter is assigned into.
  48.     The function being called does not need to know if the variable
  49.     is being passed by value or by address.
  50.  
  51.     Built-in functions and object functions always accept their
  52.     arguments as addresses, thus there is no need to use '&' when
  53.     calling built-in functions.
  54.