[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

20 Scoping

By default, FreeM local variables and their values are scoped to the entire process, meaning that any function or subroutine can access and modify their values. This can lead to pernicious bugs.

M provides the NEW command to work around these issues. When NEW is called with a local variable as its argument, FreeM will scope the variable to the process stack frame in which the NEW command occured. When exiting the stack frame (i.e. with the QUIT command), FreeM will restore the variable to its value prior to being NEWed.

Example

MYRTN ;
  S J=1 ; set local variable J to 1
  W J,! ; this will output "1"
  D X   ; execute subroutine X
  W J,! ; this will output "1", as the value of J was restored
  Q
  ;;
X ;
  N J   ; stack J
  S J=6 ; set its value to 6
  W J,! ; this will output "6"
  Q     ; quit from the subroutine, destroying its stack frame
  ;;

This document was generated on May 5, 2025 using texi2html 5.0.