Locals

From MiniScript Wiki
Revision as of 15:23, 3 June 2020 by JoeStrout (talk | contribs) (Created page with "'''locals''' is a reference to the set of local variables. It's a map where each key is an identifier string, and the value is the value of that variable. Because assignment...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

locals is a reference to the set of local variables. It's a map where each key is an identifier string, and the value is the value of that variable.

Because assignments and identifier look-up always try local variables first anyway, explicit use of the locals function is rarely needed.

One common use in Mini Micro is to tell whether an import module is being actually being run as the main program. In such a case, it will be true that locals == globals at the file scope (i.e. not inside any explicitly defined function). For examples, look at the bottom of any module in /sys/lib; when loaded and run directly, these modules run unit tests or otherwise do something useful.

See also: globals, outer.