File:  [Coherent Logic Development] / freem / doc / freem.texi
Revision 1.62: download - view: text, annotated - select for diffs
Mon May 19 13:14:35 2025 UTC (5 months, 2 weeks ago) by snw
Branches: MAIN
CVS tags: HEAD
Bump version

    1: \input texinfo
    2: @paragraphindent 0
    3: @setfilename freem.info
    4: @settitle The FreeM Manual
    5: 
    6: @copying
    7: This manual is for FreeM, (version 0.65.1-rc1), which is a free software implementation of the M programming language.
    8: 
    9: Print-optimized versions of this book are typeset in @emph{Computer Modern} by the author using the @emph{GNU Texinfo} tools.
   10: 
   11: Copyright @copyright{} 2014-2025 Coherent Logic Development LLC
   12: 
   13: @quotation
   14: Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover texts, and with no Back-Cover Texts.
   15: @end quotation
   16: @end copying
   17: 
   18: @titlepage
   19: 
   20: @title The FreeM Manual
   21: @subtitle @sc{The Official Manual of FreeM}
   22: @subtitle Version 0.65.1-rc1
   23: @c@vskip 10pt
   24: @c@center @image{freem-logo-sm,,,,.png}
   25: @author Serena Willis
   26: @page
   27: @vskip 0pt plus 1filll
   28: @insertcopying
   29: @end titlepage
   30: @contents
   31: 
   32: @ifnottex
   33: @node Top
   34: @top The FreeM Manual
   35: 
   36: This is the official manual for the FreeM programming language.
   37: @end ifnottex
   38: 
   39: @dircategory The FreeM Manual
   40: @direntry
   41: * FreeM: (freem).                       The FreeM M programming language.
   42: @end direntry
   43: 
   44: @menu
   45: * Introduction::                        About the FreeM Project, its history, and its goals.
   46: * Document Conventions::                Conventions used in this manual.
   47: * A Note on Standards::                 FreeM positioning regarding the M Development Committee.
   48: * FreeM Invocation::                    How to invoke FreeM from the command line.
   49: * The FreeM Environment Daemon::        Managing shared resources in the FreeM environment.
   50: * The FreeM Direct-Mode Environment::   Executing M programs interactively.
   51: * Debugging::                           The program development cycle of FreeM.
   52: * Program Development Cycle::           How to create, edit, test, and run FreeM programs.
   53: 
   54: * Directives::                          Per-Routine Language Directives.
   55: * Intrinsic Special Variables::         Intrinsic Special Variables.
   56: * Intrinsic Functions::                 Intrinsic Functions.
   57: * OBJECT Methods::                      Methods for OBJECT variables.
   58: * STRING Methods::                      Methods for STRING variables.
   59: * Commands::                            Commands.
   60: * Structured System Variables::         Structured System Variables.
   61: * Operators::                           FreeM Operators.
   62: 
   63: * Routines::                            The units of M code in FreeM.
   64: * Types::                               FreeM data types.
   65: * Globals::                             FreeM persistent sparse arrays.
   66: * Concurrency Control::                 @code{LOCK}ing and transaction processing.
   67: * Local Variables::                     In-memory variables.
   68: * Scoping::                             Scoping in FreeM.
   69: * Decision Constructs::                 @code{IF}, @code{THEN}, @code{ELSE}, @code{$SELECT}, and postconditionals.
   70: * Branch Constructs::                   Labels, @code{GOTO}, @code{DO}, and @code{JOB}.
   71: * Loop Constructs::                     The @code{FOR} loop.
   72: * Modular Programming::                 Extrinsic functions and subroutines.
   73: * Object-Oriented Programming::         Classes and objects in FreeM.
   74: * Libraries::                           System and user libraries.
   75: * Sequential I/O::                      Processing sequential files in FreeM.
   76: * Network I/O::                         Handling network sockets in FreeM.
   77: * Extended Global References::          Accessing globals in non-default namespaces.
   78: * Global Aliasing::                     Defining alternate names for globals.
   79: * Global Mappings::                     Mapping global names to non-default namespaces.
   80: 
   81: * Asynchronous Event Handling::         Handling asynchronous events in FreeM.
   82: * Global Triggers::                     Responding to global accesses in M code.
   83: * Synchronous Event Handling::          Synchronous events in FreeM.
   84: 
   85: 
   86: * GUI Programming with MWAPI::          Creating graphical interfaces in FreeM.
   87: 
   88: * User-Defined Z Commands::             Adding your own Z commands to FreeM.
   89: * User-Defined Z Functions::            Adding your own Z functions to FreeM.
   90: * User-Defined SSVNs::                  Adding your own SSVNs to FreeM.
   91: 
   92: * Language Dialects::                   Controlling FreeM standards compliance.
   93: 
   94: * System Library Routines::             FreeM built-in library of M routines.
   95: 
   96: * Interrupt Handling::                  How FreeM handles interrupts.
   97: * Error Processing::                    How to handle errors in M program code.
   98: * FreeM Error Codes::                   Explanations of each FreeM error code.
   99: 
  100: * System Configuration::                Configuring your FreeM installation.
  101: * Accessing FreeM from C Programs::     How to use the mlib interface.
  102: 
  103: * FreeM Administrator::                 The fmadm system manager tool.
  104: * FreeM VIEW Commands and Functions::   Getting and setting info about FreeM internals.
  105: * Implementation Limits::               FreeM limitations.
  106: * US-ASCII Character Set::              The US-ASCII character set.
  107: * FreeM Project Coding Standards::      How to write code for submission to the FreeM project.
  108: 
  109: * Index::               Complete index.
  110: @end menu
  111: 
  112: @node Introduction
  113: @unnumbered Introduction
  114: 
  115: FreeM started its life as @emph{FreeMUMPS}, written for MS-DOS and ported to SCO UNIX by a mysterious individual going by the name of "Shalom ha-Ashkenaz". It was released to MUG Deutschland in 1998. In 1999, Ronald L. Fox ported FreeM to the Red Hat Linux 5 distribution of the GNU/Linux operating system. Thereafter, maintenance was taken over by the Generic Universal M Project, which changed its name first to Public Standard MUMPS and then by popular request to FreeM.
  116: 
  117: When GT.M was open-sourced in late 1999, FreeM and GUMP were essentially abandoned. L.D. Landis, the owner of the original GUMP SourceForge project, and one of FreeM's significant contributors, passed maintenance of FreeM and ownership of its SourceForge project to Serena Willis in 2014. At this point, FreeM would not compile or run on modern Linux systems, so steps were taken to remedy the most pressing issues in the codebase. Limitations on the terminal size (previously hard-coded to 80x25) were lifted, and new @code{$VIEW} functions were added to retrieve the terminal size information. @code{$X} and @code{$Y} intrinsic special variables were updated to support arbitrary terminal sizes, and FreeM was once again able to build and run.
  118: 
  119: In February of 2020, work began in earnest to build a development and support infrastructure for FreeM and begin the careful process of refining it into a more stable and robust application.
  120: 
  121: For more information on FreeM history, see @code{@emph{$PREFIX}/share/freem/doc/freem_history.*} (distributed in PostScript, PDF, and plain text formats).
  122: 
  123: @section Production Readiness
  124: 
  125: FreeM is not yet production-ready. There are several show-stopping bugs that preclude a general release for public use:
  126: 
  127: @itemize @bullet
  128: 
  129: @item
  130: @code{@ref{VIEW}} commands and @code{@ref{$VIEW()}} functions are used extensively to configure and inspect the run-time behavior of FreeM, rather than the "canonical" SSVN-based approach.
  131: 
  132: @item
  133: Server sockets are not yet implemented.
  134: 
  135: @item
  136: There are some situations that can result in segmentation faults and/or lock-ups.
  137: 
  138: @item
  139: In spite of our best efforts, this manual is not yet complete.
  140: 
  141: @end itemize
  142: 
  143: @section Contributors
  144: Current contributors denoted with a @emph{+} following their name and role.
  145: @cindex contributors, ha-Ashkenaz, Shalom
  146: @cindex contributors, Best, John
  147: @cindex contributors, Diamond, Jon
  148: @cindex contributors, Fox, Ronald L.
  149: @cindex contributors, Gerum, Winfried
  150: @cindex contributors, Kreis, Greg
  151: @cindex contributors, Landis, Larry
  152: @cindex contributors, McGlothlen, Ken
  153: @cindex contributors, Milligan, Lloyd
  154: @cindex contributors, Morris, Steve
  155: @cindex contributors, Murray, John
  156: @cindex contributors, Pastoors, Wilhelm
  157: @cindex contributors, Schell, Kate
  158: @cindex contributors, Schofield, Lyle
  159: @cindex contributors, Stefanik, Jim
  160: @cindex contributors, Trocha, Axel
  161: @cindex contributors, Walters, Dick
  162: @cindex contributors, Whitten, David
  163: @cindex contributors, Wicksell, David
  164: @cindex contributors, Willis, Serena
  165: @cindex contributors, Zeck, Steve
  166: 
  167: @itemize @bullet
  168: 
  169: @item
  170: Shalom ha-Ashkenaz (Original Implementer)
  171: 
  172: @item
  173: John Best (IBM i and OS/400)
  174: 
  175: @item
  176: Jon Diamond (Library, Utilities, Conformance)
  177: 
  178: @item
  179: Ronald L. Fox (Initial port to Red Hat 5/libc-6)
  180: 
  181: @item
  182: Winfried Gerum (Code, Advice, MTA coordination)
  183: 
  184: @item
  185: Greg Kreis (Hardhats coordination, Dependencies)
  186: 
  187: @item
  188: Larry Landis (Coordination, Code, Documentation)
  189: 
  190: @item
  191: Rick Marshall (Testing, MDC Conformance) @emph{+}
  192: 
  193: @item
  194: Ken McGlothlen (Apple Silicon build/test environment, proofreading of documentation) @emph{+}
  195: 
  196: @item
  197: Lloyd Milligan (Code, Testing, Documentation)
  198: 
  199: @item
  200: Steve Morris (Code, Microsoft)
  201: 
  202: @item
  203: John Murray (Code, Conformance)
  204: 
  205: @item
  206: Wilhelm Pastoors (Testing, Documentation)
  207: 
  208: @item
  209: Kate Schell (Coordination, Conformance, MTA, MDC, Advice)
  210: 
  211: @item
  212: Lyle Schofield (Advice, Prioritization, Tracking, Project Management)
  213: 
  214: @item
  215: Jim Stefanik (GNU/Linux on s390x, IBM AIX, IBM z/OS)
  216: 
  217: @item
  218: Axel Trocha (Code, Utilities)
  219: 
  220: @item
  221: Dick Walters (Project Lead, Chief Coordinator, MTA)
  222: 
  223: @item
  224: David Whitten (QA Test Suite, MDC, Advice) @emph{+}
  225: 
  226: @item
  227: David Wicksell (Debugging, Code, Testing) @emph{+}
  228: 
  229: @item
  230: Serena Willis (Current Maintainer and Project Lead) @emph{+}
  231: 
  232: @item
  233: Steve Zeck (Code)
  234: 
  235: @end itemize
  236: 
  237: @node Document Conventions
  238: @chapter Document Conventions
  239: @cindex document conventions
  240: @cindex conventions
  241: 
  242: @section Formatting Conventions
  243: 
  244: This manual uses the following formatting conventions:
  245: @itemize
  246: @item Code examples, filesystem paths, and commands are presented in @code{monospace}
  247: @item Placeholders where the reader is expected to supply a replacement value are presented in @code{@emph{monospace italics}}, and depending on context, may be surrounded by angle brackets
  248: @item New terminology is introduced in @emph{proportional italics}
  249: @end itemize
  250: 
  251: @section Definitions
  252: 
  253: FreeM uses abbreviations for common language elements:
  254: 
  255: @table @asis
  256: @item @emph{$PREFIX}
  257: Refers to the base filesystem location within which FreeM is installed. For most distribution methods of FreeM, @emph{$PREFIX} represents either @code{/} or @code{/usr/local}.
  258: @item @emph{dlabel}
  259: Refers to a label in an M routine, beginning in the first column of the line. Can be a @emph{name} or an @emph{intlit}.
  260: @item @emph{entryref}
  261: Refers to an M routine entry point, denoted in the format @code{@emph{dlabel} [+@emph{intexpr}][^@emph{routine}]}.
  262: @item @emph{expr}
  263: Refers to any expression. Often presented in the format @emph{expr V <type>}, where @emph{V} means @emph{giving}; e.g., @emph{expr V lvn} means @emph{expression giving local variable name}.
  264: @item @emph{glvn}
  265: Refers to the name of an M global, local, or structured system variable.
  266: @item @emph{gvn}
  267: Refers to the name of an M global variable.
  268: @item @emph{intexpr}
  269: Refers to an integer expression.
  270: @item @emph{intlit}
  271: Refers to an integer literal.
  272: @item @emph{ISV}, @emph{isv}
  273: Refers to an M intrinsic special variable; @code{$JOB} and @code{$IO} are examples of ISVs.
  274: @item @emph{L}
  275: Indicates a @emph{list} of the following item, e.g., @emph{L gvn} means @emph{list of global variable names}.
  276: @item @emph{lvn}
  277: Refers to the name of an M local variable.
  278: @item @emph{postcondition}
  279: A @emph{tvexpr} immediately following a command verb affecting that command's execution.
  280: @item @emph{strlit}
  281: Refers to an M string literal.
  282: @item @emph{ssvn}
  283: Refers to the name of an M structured system variable.
  284: @item @emph{tvexpr}
  285: Refers to a truth-valued expression, i.e., an expression interpreted as a truth value.
  286: @end table
  287: 
  288: @node A Note on Standards
  289: @chapter A Note on Standards
  290: @cindex MDC
  291: @cindex M Development Committee
  292: @cindex ANSI X11.1
  293: @cindex standards, ANSI
  294: @cindex standards, MDC
  295: 
  296: FreeM attempts to implement as many features as possible from the M Development Committee's unpublished @emph{Millennium Draft Standard}, as well as its predecessors.
  297: 
  298: The maintainer of FreeM (who is also the author of this book) is largely in favor of standardization efforts, and hopes that the MDC will resume activities, and will happily participate if it does so in an open, public, transparent, and democratic manner. Until then, however, FreeM will attempt to improve the M language, in cooperation with other free software M implementers where possible. Any breaking changes introduced in future MDC releases of the @emph{Standard} (such as the rumored @emph{M5}) which prove incompatible with FreeM will be handled via the @code{$DIALECT} special variable (to be changed to @code{$ZDIALECT} in a coming release).
  299: 
  300: The conformance document required per the @emph{Standard} should be installed as a @code{man} page on any computer system where FreeM is made available. Simply type @code{man freem_conformance} to access.
  301: 
  302: @node FreeM Invocation
  303: @chapter FreeM Invocation
  304: @cindex invocation, command-line
  305: @cindex options, command-line
  306: 
  307: @section Synopsis
  308: @example
  309: $ @command{./freem} [@emph{OPTIONS}...] [[-r <entryref>] | [--routine=<entryref>]]
  310: @end example
  311: 
  312: When FreeM loads, it searches the @code{SYSTEM} namespace for the @code{%SYSINIT} routine, and begins executing it.
  313: 
  314: When @code{-r} or @code{--routine} are passed on the command line, FreeM will load and run the specified routine after running @code{%SYSINIT}. Beginning with FreeM 0.1.7, routines invoked in this manner are no longer required to perform their own namespace setup with @code{VIEW} commands.
  315: 
  316: @section %SYSINIT Routine
  317: 
  318: The @code{%SYSINIT} routine runs every time a FreeM interpreter process starts. This routine defines some useful constants, enables handling of @code{TRIGGER} events, and handles the execution of code passed via the @code{-x|--execute} or routines passed via @code{-r|--routine}.
  319: 
  320: Do not modify the supplied @code{%SYSINIT} routine to add site-specific startup items. Instead, create a @code{LCLINIT} routine in the @code{USER} namespace of one or more environments. @code{%SYSINIT} will automatically run @code{LCLINIT} each time it starts.
  321: 
  322: @section Command-Line Options
  323: @cindex options, command-line
  324: 
  325: @table @asis
  326: 
  327: @item @option{-d}, @option{--daemon}
  328: Starts the FreeM environment daemon, exactly one of which must be running at all times in order for FreeM interpreter and fmadm processes to function.
  329: 
  330: @item @option{-e}, @option{--environment}
  331: Selects the environment to be used. If no environment is specified, @code{DEFAULT} is used.
  332: 
  333: @item @option{-k}, @option{--nofork}
  334: When used with @option{-d} or @option{--daemon}, causes the FreeM environment daemon to run instead in the foreground. Useful for debugging.
  335: 
  336: @item @option{-S}, @option{--shmsize}
  337: When used with @option{-d} or @option{--daemon}, specifies the number of bytes of shared memory FreeM will allocate for the @code{LOCK} table, job table, and IPC table. This will determine the maximum number of concurrent FreeM processes and @code{LOCK}s available in this environment. 
  338: 
  339: @item @option{-c}, @option{--config}
  340: Specify a configuration file other than @code{$PREFIX/etc/freem.conf}.
  341: 
  342: @item @option{-h}, @option{--help}
  343: Display a help message showing valid FreeM options.
  344: 
  345: @item @option{-i}, @option{--import}
  346: Causes your UNIX environment variables to be imported into FreeM's local symbol table.
  347: 
  348: @item @option{-f}, @option{--filter}
  349: Allows your M routines to be used as UNIX filters.
  350: 
  351: @item @option{-n @emph{<namespace-name>}}, @option{--namespace=@emph{<namespace-name>}}
  352: Selects the FreeM namespace to be entered on startup. Must be defined in @file{/etc/<environment>/freem.conf}.
  353: 
  354: @item @option{-r @emph{<entryref>}}, @option{--routine=@emph{<entryref>}}
  355: Causes @code{<entryref>} to be executed at load, instead of @code{%SYSINIT}.
  356: 
  357: @item @option{--standard=@emph{<standard>}}
  358: Sets the default FreeM dialect to use for new routine buffers.
  359: 
  360: Valid values for @code{@emph{<standard>}} are as follows:
  361: 
  362: @table @code
  363: @item @code{M77}
  364: Restricts FreeM to use only features specified by the 1977 M standard.
  365: @item @code{M84}
  366: Restricts FreeM to use only features specified by the 1984 M standard.
  367: @item @code{M90}
  368: Restricts FreeM to use only features specified by the 1990 M standard.
  369: @item @code{M95}
  370: Restricts FreeM to use only features specified by the 1995 M standard.
  371: @item @code{MDS}
  372: Restricts FreeM to use only features proposed by the Millennium Draft Standard.
  373: @item @code{M5}
  374: Restricts FreeM to use only features proposed by the upcoming M5 standard.
  375: @item @code{FREEM}, @code{EXTENDED}
  376: Removes all standards-based restrictions and allows full access to all FreeM features. This is the default value of @code{$DIALECT}.
  377: @end table
  378: 
  379: Please note that FreeM is not entirely standards-compliant, regardless of the value of @code{@emph{<standard>}}.
  380: 
  381: @item @option{-v}, @option{--version}
  382: Displays FreeM version information.
  383: 
  384: @item @option{-x @emph{<mcode>}}, @option{--execute=@emph{<mcode>}}
  385: Executes M code @code{<mcode>} at startup.
  386: 
  387: @end table
  388: 
  389: @section Using FreeM for Shell Scripting
  390: @cindex routines, as shell scripts
  391: @cindex shebang line
  392: @cindex shell scripting
  393: 
  394: FreeM M routines can be used as shell scripts by providing a @emph{shebang} line beginning with @code{#!/path/to/freem} as the first line of the routine.
  395: The following example presumes that FreeM is installed at @file{/usr/local/bin/freem} and uses the @code{USER} namespace:
  396: 
  397: @example
  398: #!/usr/local/bin/freem
  399: MYSCRIPT ;
  400:  SET ^$JOB($JOB,"NAMESPACE")="USER"
  401:  WRITE "This is output from an M routine used as a shell script.",!
  402:  Q
  403: @end example
  404: 
  405: Currently, the script needs to have a @file{.m} file extension. You will also need to select an appropriate namespace in your script using the @code{SET ^$JOB($JOB,"NAMESPACE")="@emph{<namespace>}"} command before attempting to call other routines or access globals.
  406: 
  407: You will also need to set the script's permissions to @emph{executable} in order for this to work:
  408: 
  409: @example
  410: $ chmod +x @emph{myscript.m}
  411: @end example
  412: 
  413: @node The FreeM Environment Daemon
  414: @chapter The FreeM Environment Daemon
  415: @cindex daemon, freem
  416: 
  417: The FreeM environment daemon manages shared resources for a given FreeM environment. These include the lock table, job table, inter-process communication, and concurrency control for transaction processing. Unlike some M implementations, the FreeM environment daemon does @emph{not} function as a write daemon for global storage.
  418: 
  419: One daemon process is required per FreeM environment, and can be started in the following ways, in order of preference:
  420: 
  421: @example
  422: $ sudo fmadm start environment [-e=<environment-name>]
  423: @end example
  424: 
  425: @example
  426: $ freem --daemon [--nofork] [--environment=<environment-name>] [--shmsize=<bytes>]
  427: @end example
  428: 
  429: If the daemon is started with @option{--nofork}, it will run in the foreground and its output will be reflected on the terminal. Otherwise, the daemon will run as a child process in the background and immediately return terminal control to the shell. The latter option is recommended in most cases.
  430: 
  431: The @option{--environment} option will start the daemon for the specified @emph{environment-name}. The default environment, if unspecified, is called @code{DEFAULT}. If using an environment other than @code{DEFAULT}, interpreter processes that wish to also connect to the same environment must also use the @option{--environment} option when starting, and @code{libfreem} clients must also pass the environment name as the first argument to the @code{freem_init()} function. Environments allow you to run multiple, isolated instances of FreeM on the same machine, whose globals and routines are distinct and unique.
  432: 
  433: The @option{--shmsize} option specifies the size in bytes of the FreeM shared memory segment. The default is 16,777,216 bytes (16 megabytes). Increasing the size of the FreeM shared memory segment will, at the cost of increased memory usage, increase the number of concurrent jobs and lock table entries available to the environment; decreasing the size of the segment will have the expected opposite effect. Note that you must also pass @option{--shmsize} with the same number of bytes to any interpreter process to be used with an environment whose daemon uses a non-default shared memory segment size.
  434: 
  435: Attempting to start a FreeM interpreter process without a daemon running with the same environment name will result in an error.
  436: 
  437: @node The FreeM Direct-Mode Environment
  438: @chapter The FreeM Direct-Mode Environment
  439: @cindex command line interface
  440: @cindex direct mode
  441: @cindex execution, interactive
  442: @cindex modes, programmer
  443: 
  444: 
  445: The FreeM direct-mode environment is the mode entered when FreeM is invoked without the use of @option{-r @emph{<entryref>}} or @option{--routine=@emph{<entryref>}}:
  446: 
  447: @example
  448: Coherent Logic Development FreeM version 0.65.1-rc1 (x86_64-pc-linux-gnu)
  449: Copyright (C) 2014, 2020, 2021 Coherent Logic Development LLC
  450: 
  451: 
  452: USER>
  453: @end example
  454: 
  455: The prompt (@code{DEFAULT.USER>}) displays the current environment and namespace, @code{DEFAULT} and @code{USER}, respsectively. If any uncommitted direct-mode transactions have been started, the prompt will change to reflect the current value of @code{@ref{$TLEVEL}}:
  456: 
  457: @example
  458: TL1:DEFAULT.USER>
  459: @end example
  460: 
  461: In the above example, @code{TL1} indicates that @code{@ref{$TLEVEL}} is currently @emph{1}.
  462: 
  463: @section Direct-Mode Commands
  464: 
  465: When you are in direct mode, in addition to M commands, a number of internal commands are available to help developers be more productive:
  466: 
  467: @table @asis
  468: 
  469: @item @command{?}
  470: Accesses FreeM online help. Requires GNU @command{info(1)} to be installed on your local system.
  471: 
  472: @item @command{events}
  473: Writes a list of @emph{event classes} and their @code{ABLOCK} counts:
  474: 
  475: @example
  476: DEFAULT.USER> events
  477:  
  478: Event Class          Processing Mode ABLOCK Count
  479: -----------          --------------- ------------
  480: COMM                 Disabled        0
  481: HALT                 Disabled        0
  482: IPC                  Disabled        0
  483: INTERRUPT            Disabled        0
  484: POWER                Disabled        0
  485: TIMER                Disabled        0
  486: USER                 Disabled        0
  487: WAPI                 Disabled        0
  488: TRIGGER              Disabled        0
  489: @end example
  490: 
  491: 
  492: @anchor{trantab}
  493: @item @command{trantab}
  494: Displays information about any uncommitted transactions currently in-flight for this process.
  495: 
  496: @anchor{glstat}
  497: @item @command{trantab}
  498: Displays statistics about globals that have been opened in the current FreeM process.
  499: 
  500: @anchor{jobtab}
  501: @item @command{jobtab}
  502: Displays a summary of the FreeM job table.
  503: 
  504: @anchor{locktab}
  505: @item @command{locktab}
  506: Displays a list of @code{LOCK}s held in the current environment.
  507: 
  508: @anchor{rbuf}
  509: @item @command{rbuf}
  510: Lists the status of all FreeM routine buffers.
  511: 
  512: @anchor{wh}
  513: @item @command{wh}
  514: Forces an immediate flush of this process's @code{readline} history buffer to disk.
  515: 
  516: @anchor{shmstat}
  517: @item @command{shmstat}
  518: Displays the configuration of FreeM shared memory. Intended only for advanced debugging of the FreeM environment.
  519: 
  520: @anchor{shmpages}
  521: @item @command{shmpages}
  522: Lists the status of each FreeM shared memory page. Intended only for advanced debugging of the FreeM environment.
  523: 
  524: @anchor{history}
  525: @item @command{history}
  526: Prints a list of all the direct-mode commands you have entered across all sessions.
  527: 
  528: @anchor{rcl}
  529: @item @command{rcl @emph{<history-index>}}
  530: Allows you to recall command number @emph{<history-index>} and run it again. Obtain the value for @emph{<history-index>} from the output of the @command{history} command.
  531: 
  532: @item @command{!!}
  533: Launches a subshell within the FreeM direct mode, allowing the user to run operating system commands.
  534: 
  535: @example
  536: DEFAULT.USER> !!
  537: 
  538: Type Ctrl-D to exit from the shell
  539: $ uname -a
  540: Linux hesperos 4.19.0-17-amd64 #1 SMP Debian 4.19.194-3 (2021-07-18) x86_64 GNU/Linux
  541: $ exit
  542: 
  543: DEFAULT.USER> 
  544: @end example
  545: 
  546: @item @command{!@emph{<external-command>}}
  547: Invokes a shell to run @emph{<external-command>} from within FreeM. This temporarily disables @command{SIGALRM} handling in FreeM, which may interrupt the use of event-driven M programming commands including @command{ASTART} and @command{ASTOP}.
  548: 
  549: If the @command{>} character is supplied immediately preceding @emph{<external-command>}, FreeM will append the contents of an M local or global variable referenced in @code{^$JOB($JOB,"PIPE_GLVN")} to the standard input stream of @emph{<external-command>}.
  550: 
  551: If the @command{<} character is supplied immediately preceding @emph{<external-command>}, FreeM will take the standard output stream of @emph{<external-command>} and store it in M local or global variable referenced by @code{^$JOB($JOB,"PIPE_GLVN")}.
  552: 
  553: The data value in the unsubscripted M local or global contains the number of lines in the input or output. Subscripts @code{(1)..(@emph{n})} contain the data for lines 1-@emph{n}.
  554: 
  555: @end table
  556: 
  557: @cindex HALT, in direct-mode
  558: If you issue a @code{@ref{HALT}} command at the direct-mode prompt, you will exit out of FreeM. However, if you issue a @code{@ref{HALT}} command when @code{@ref{$TLEVEL}} is greater than zero, you will be given the opportunity to commit or rollback any pending transactions:
  559: 
  560: @example
  561: DEFAULT.USER> TSTART
  562:  
  563: 
  564: TL1:DEFAULT.USER> SET ^MYGLOBAL=1
  565:  
  566:  
  567: TL1:DEFAULT.USER> HALT
  568:  
  569: UNCOMMITTED TRANSACTIONS EXIST:
  570:  
  571:  $TLEVEL 1*
  572:   Operations for Transaction ID: k8xj1de
  573:   1:	action = 0  key = ^MYGLOBAL  data = 1
  574:  
  575: Would you like to c)ommit or r)ollback the above transactions and their operations? ($TLEVEL = 1) r
  576: 
  577: 
  578: Transactions have been rolled back.
  579: @end example
  580: 
  581: In the above example, the user selected @code{r} to rollback the single pending transaction.
  582: 
  583: @section REPL Functionality
  584: @cindex REPL, direct-mode
  585: 
  586: FreeM direct mode allows you to enter M expressions directly from the direct-mode prompt, as long as they begin with a number:
  587: 
  588: @example
  589: DEFAULT.USER> S DENOM=10
  590:  
  591:  
  592: DEFAULT.USER> 100/DENOM
  593:  
  594: 10
  595: DEFAULT.USER> 
  596: @end example
  597: 
  598: Such expressions will be immediately evaluated, and the result printed on @code{@ref{$IO}}.
  599: 
  600: @node Debugging
  601: @chapter Debugging
  602: @cindex debugging
  603: 
  604: @section Debugging Synopsis
  605: FreeM includes an interactive debugger, entered using the @code{BREAK "DEBUG"} command. The debugger is also entered if @code{Ctrl-C} is pressed, @code{Ctrl-C} handling is enabled, and you are in direct mode.
  606: 
  607: If you would like to enter the debugger automatically each time an error is encountered, add the following to your @code{LCLINIT} routine:
  608: 
  609: @example
  610: S $ETRAP="B ""DEBUG"""
  611: @end example
  612: 
  613: @section Debugging Commands
  614: The debugger uses its own unique command language, where M commands are unavailable. Commands are as follows:
  615: 
  616: @table @asis
  617: @item @code{exit}, @code{quit}
  618: Exits the debugger and returns to direct mode or normal program execution.
  619: @item @code{e} @emph{glvn}, @code{examine} @emph{glvn}
  620: Prints the value of @emph{glvn} to the terminal.
  621: @item @code{t}, @code{trace}
  622: Toggles @emph{trace mode} on and off. When trace mode is on, FreeM will display information about each @code{DO} or @code{GOTO} command encountered, including the routine which invoked the branch, which type of branch was invoked, and the target of the branch.
  623: @item @code{s}, @code{step}
  624: Single-steps through FreeM code command-by-command.
  625: @item @code{n}, @code{next}
  626: Single-steps through FreeM code line-by-line.
  627: @item @code{c}, @code{cont}, @code{continue}
  628: Resumes normal program execution, disabling single-step mode.
  629: @item @code{bt}, @code{backtrace}
  630: Produces a stack trace.
  631: @item @code{h}, @code{halt}
  632: Halts the process being debugged and returns control to the operating system.
  633: @item @code{w [[+|-|?]@emph{<glvn>}]}, @code{watch [[+|-|?]@emph{<glvn>}]}
  634: With no arguments, toggles watchpoints on and off. With @code{+}, adds @emph{<glvn>} to the watchlist. With @code{-}, removes @emph{<glvn>} from the watchlist. With @code{?}, queries the watch status of @emph{<glvn>}.
  635: @end table
  636: 
  637: @node Program Development Cycle
  638: @chapter Program Development Cycle
  639: @cindex program development
  640: 
  641: This chapter covers the essential activities of program development in the FreeM environment, including viewing, creating, editing, and running routines.
  642: 
  643: @node Directives
  644: @chapter Directives
  645: @cindex directives
  646: 
  647: In FreeM, a directive is an instruction embedded in an M comment, and passed to the interpreter to affect a change that is specific to the current routine only.
  648: 
  649: The format of a directive is @code{;%@emph{<directive-name>}}, where @code{@emph{<directive-name>}} is one of the directives listed below.
  650: 
  651: @menu
  652: * %DIALECT::            Sets the M dialect in effect.
  653: @end menu
  654: 
  655: @anchor{%DIALECT}
  656: @section %DIALECT
  657: @cindex %DIALECT
  658: @cindex directives, %DIALECT
  659: 
  660: Sets the M dialect in effect for the current routine buffer; also sets the @code{$DIALECT} special variable to match. See also @ref{$DIALECT}.
  661: 
  662: @emph{Syntax}
  663: 
  664: @example
  665: ;%DIALECT @emph{<dialect>}
  666: @end example
  667: 
  668: Valid values for @code{@emph{<dialect>}} are as follows:
  669: 
  670: @table @code
  671: @item @code{M77}
  672: Restricts FreeM to use only features specified by the 1977 M standard.
  673: @item @code{M84}
  674: Restricts FreeM to use only features specified by the 1984 M standard.
  675: @item @code{M90}
  676: Restricts FreeM to use only features specified by the 1990 M standard.
  677: @item @code{M95}
  678: Restricts FreeM to use only features specified by the 1995 M standard.
  679: @item @code{MDS}
  680: Restricts FreeM to use only features proposed by the Millennium Draft Standard.
  681: @item @code{M5}
  682: Restricts FreeM to use only features proposed by the upcoming M5 standard.
  683: @item @code{FREEM}, @code{EXTENDED}
  684: Removes all standards-based restrictions and allows full access to all FreeM features. This is the default value of @code{%DIALECT}.
  685: @end table
  686: 
  687: Please note that FreeM is not entirely standards-compliant, regardless of the value of @code{%DIALECT}.
  688: 
  689: 
  690: @node Intrinsic Special Variables
  691: @chapter Intrinsic Special Variables
  692: @cindex variables, intrinsic special
  693: 
  694: @menu
  695: * $DEVICE::                  $IO device status.
  696: * $DIALECT::                 Current M dialect.
  697: * $ECODE::                   Latest M error code.
  698: * $ESTACK::                  Error stack info.
  699: * $ETRAP::                   Standard error handler code.
  700: * $HOROLOG::                 Current date and time.
  701: * $IO::                      Current I/O device.
  702: * $JOB::                     PID of current process.
  703: * $KEY::                     Characters terminating last @code{READ} command.
  704: * $PDISPLAY::                Current primary MWAPI display.
  705: * $PRINCIPAL::               I/O channel of terminal.
  706: * $REFERENCE::               Most recent global reference.
  707: * $QUIT::                    Whether a @code{QUIT} command requires an argument in the current execution context.
  708: * $STACK::                   Current program execution stack level.
  709: * $STORAGE::                 Number of bytes available in the heap.
  710: * $SYSTEM::                  MDC system ID of FreeM.
  711: * $TEST::                    Truth value of last conditional expression or result of certain @code{LOCK} operations.
  712: * $TLEVEL::                  Current level of transaction nesting.
  713: * $WITH::                    Current variable prefix set by @code{ZWITH} command.
  714: * $X::                       Current horizontal screen position.
  715: * $Y::                       Current vertical screen position.
  716: * $ZA::                      Current position of file on @code{$IO}.
  717: * $ZB::                      Most recent keystroke.
  718: * $ZCONTROLC::               Control-C handling flag.
  719: * $ZDATE::                   Current date in locale-specific representation.
  720: * $ZERROR::                  Last error message.
  721: * $ZHOROLOG::                Date and time, including milliseconds.
  722: * $ZINRPT::                  State of the interrupt enable/disable flag.
  723: * $ZJOB::                    PID of parent process, if applicable.
  724: * $ZLOCAL::                  Last local variable reference.
  725: * $ZNAME::                   Name of current M routine.
  726: * $ZPRECISION::              Digits of arithmetical precision.
  727: * $ZREFERENCE::              Last gvn referenced.
  728: * $ZSYSTEM::                 Return value of last external command.
  729: * $ZTIME::                   Current time in locale-specific representation.
  730: * $ZTRAP::                   Entryref to be executed on error condition.
  731: * $ZUT::                     Microseconds since the UNIX epoch.
  732: * $ZVERSION::                Version of FreeM and GNU host triplet.
  733: @end menu 
  734: 
  735: @node $DEVICE
  736: @section $DEVICE
  737: @cindex $DEVICE
  738: @cindex intrinsic special variables, $DEVICE
  739: 
  740: Returns the status of the device currently in use.
  741: 
  742: If @code{$DEVICE} returns @emph{1}, an error condition exists on the current device. In this case, there will be two additional fields separated by commas, indicating the internal FreeM error code representing the error present on the device and a text explanation of the error.
  743: 
  744: @node $DIALECT
  745: @section $DIALECT
  746: @cindex $DIALECT
  747: @cindex intrinsic special variables, $DIALECT
  748: 
  749: Returns or sets the language dialect of the current routine.
  750: 
  751: Valid values for @code{$DIALECT} are as follows:
  752: 
  753: @table @code
  754: @item @code{M77}
  755: Restricts FreeM to use only features specified by the 1977 M standard.
  756: @item @code{M84}
  757: Restricts FreeM to use only features specified by the 1984 M standard.
  758: @item @code{M90}
  759: Restricts FreeM to use only features specified by the 1990 M standard.
  760: @item @code{M95}
  761: Restricts FreeM to use only features specified by the 1995 M standard.
  762: @item @code{MDS}
  763: Restricts FreeM to use only features proposed by the Millennium Draft Standard.
  764: @item @code{M5}
  765: Restricts FreeM to use only features proposed by the upcoming M5 standard.
  766: @item @code{FREEM}, @code{EXTENDED}
  767: Removes all standards-based restrictions and allows full access to all FreeM features. This is the default value of @code{$DIALECT}.
  768: @end table
  769: 
  770: Please note that FreeM is not entirely standards-compliant, regardless of the value of @code{$DIALECT}.
  771: 
  772: @node $ECODE
  773: @section $ECODE
  774: @cindex $ECODE
  775: @cindex intrinsic special variables, $ECODE
  776: 
  777: Returns a comma-delimited list of error conditions currently present, and is writable. An empty @code{$ECODE} indicates no errors.
  778: 
  779: Writing a value in the format @code{,<error-code>,} into @code{$ECODE} will raise that error condition.
  780: 
  781: @node $ESTACK
  782: @section $ESTACK
  783: @cindex $ESTACK
  784: @cindex intrinsic special variables, $ESTACK
  785: 
  786: Returns the depth of the program execution stack since the last time @code{$ESTACK} was @code{NEW}ed. @code{NEW}-able, but not @code{SET}-able. Differs from the @code{@ref{$STACK}} ISV in that it is @code{@ref{NEW}}-able, and resets to a value of 0 when @code{@ref{NEW}}ed.
  787: 
  788: @node $ETRAP
  789: @section $ETRAP
  790: @cindex $ETRAP
  791: @cindex intrinsic special variables, $ETRAP
  792: 
  793: Sets or retrieves the M code that is run when an error is encountered or @code{@ref{$ECODE}} is set to a non-blank value. @code{$ETRAP} code executes when @code{$ECODE} becomes non-blank.
  794: 
  795: 
  796: @node $HOROLOG
  797: @section $HOROLOG
  798: @cindex $HOROLOG
  799: @cindex intrinsic special variables, $HOROLOG
  800: 
  801: Returns a string containing the current date and time as @code{<days>,<seconds>}, where @code{<days>} represents the number of days since the M epoch (midnight on 31 December 1840),
  802: and @code{<seconds>} represents the number of seconds since the most recent midnight.
  803: 
  804: @cartouche
  805: @quotation
  806: @emph{FreeM Extension}
  807: 
  808: In FreeM, @code{$HOROLOG} is @code{@ref{SET}}table. Setting @code{$HOROLOG} will set the system clock if your user account has the appropriate permissions. If your user account does not have permissions to modify the system clock, FreeM will raise a @code{ZPROTECT} error.
  809: @end quotation
  810: @end cartouche
  811: 
  812: @node $IO
  813: @section $IO
  814: @cindex $IO
  815: @cindex intrinsic special variables, $IO
  816: 
  817: Represents the current input/output device. Read-only.
  818: 
  819: @node $JOB
  820: @section $JOB
  821: @cindex $JOB
  822: @cindex intrinsic special variables, $JOB
  823: 
  824: Represents the process ID of the FreeM instance currently in use.
  825: 
  826: @node $KEY
  827: @section $KEY
  828: @cindex $KEY
  829: @cindex intrinsic special variables, $KEY
  830: 
  831: Represents the sequence of control characters that terminated the last @code{@ref{READ}} command on @code{@ref{$IO}}.
  832: 
  833: @node $PDISPLAY
  834: @section $PDISPLAY
  835: @cindex $PDISPLAY
  836: @cindex intrinsic special variables, $PDISPLAY
  837: 
  838: Represents the current principal display for M Windowing API operations. Commonly used as an index into the @code{@ref{^$DISPLAY}} structured system variable.
  839: 
  840: @node $PRINCIPAL
  841: @section $PRINCIPAL
  842: @cindex $PRINCIPAL
  843: @cindex intrinsic special variables, $PRINCIPAL
  844: 
  845: Represents the primary input/output device. Usually a terminal or virtual terminal.
  846: 
  847: @node $REFERENCE
  848: @section $REFERENCE
  849: @cindex $REFERENCE
  850: @cindex intrinsic special variables, $REFERENCE
  851: 
  852: Returns the last @emph{glvn} referenced. Can be @code{@ref{SET}}, and also stacked with @code{@ref{NEW}}.
  853: 
  854: @node $QUIT
  855: @section $QUIT
  856: @cindex $QUIT
  857: @cindex intrinsic special variables, $QUIT
  858: 
  859: If the current execution context was invoked as an extrinsic function, @code{$QUIT} returns @emph{1}. Otherwise, returns @emph{0}.
  860: 
  861: When @code{$QUIT} returns @emph{1}, a subsequent @code{@ref{QUIT}} command must have an argument.
  862: 
  863: @node $STACK
  864: @section $STACK
  865: @cindex $STACK
  866: @cindex intrinsic special variables, $STACK
  867: 
  868: Represents the current stack level.
  869: 
  870: @node $STORAGE
  871: @section $STORAGE
  872: @cindex $STORAGE
  873: @cindex intrinsic special variables, $STORAGE
  874: 
  875: Represents the number of bytes of free space available in FreeM's heap.
  876: 
  877: @node $SYSTEM
  878: @section $SYSTEM
  879: @cindex $SYSTEM
  880: @cindex intrinsic special variables, $SYSTEM
  881: 
  882: Returns the MDC system ID of FreeM, as well as the environment ID of the current environment.
  883: 
  884: @node $TEST
  885: @section $TEST
  886: @cindex $TEST
  887: @cindex intrinsic special variables, $TEST
  888: 
  889: @code{$TEST} is a writable, @code{@ref{NEW}}-able ISV that is @emph{1} if the most recently evaluated expression was @emph{true}. Otherwise, returns @emph{0}.
  890: 
  891: @code{$TEST} is implicitly @code{NEW}ed when entering a new stack frame for extrinsic functions and argumentless @code{@ref{DO}}. @code{$TEST}
  892: is @emph{not} implicitly @code{NEW}ed when a new stack frame is entered with an argumented @code{DO}.
  893: 
  894: For single-line @code{@ref{IF}} or @code{@ref{ELSE}} expressions, you may use @code{@ref{THEN}} to stack @code{$TEST} until the end of the line. All new code should employ @code{THEN} in this manner, as stacking @code{$TEST} prevents a wide range of coding errors that can be very challenging to detect and eliminate.
  895: 
  896: @node $TLEVEL
  897: @section $TLEVEL
  898: @cindex $TLEVEL
  899: @cindex intrinsic special variables, $TLEVEL
  900: 
  901: Returns a numeric value indicating the current level of transaction nesting in the process. When @code{$TLEVEL} is greater than @emph{0},
  902: uncommitted transactions exist.
  903: 
  904: @node $WITH
  905: @section $WITH
  906: @cindex $WITH
  907: @cindex intrinsic special variables, $WITH
  908: 
  909: Returns the variable prefix set by the @code{@ref{ZWITH}} command.
  910: 
  911: @node $X
  912: @section $X
  913: @cindex $X
  914: @cindex intrinsic special variables, $X
  915: 
  916: Represents the current column position of the FreeM cursor.
  917: 
  918: @cartouche
  919: @quotation
  920: In FreeM, setting @code{$X} will move the FreeM cursor.
  921: @end quotation
  922: @end cartouche
  923: 
  924: 
  925: @node $Y
  926: @section $Y
  927: @cindex $Y
  928: @cindex intrinsic special variables, $Y
  929: 
  930: Represents the current row position of the FreeM cursor.
  931: 
  932: @cartouche
  933: @quotation
  934: In FreeM, setting @code{$Y} will move the FreeM cursor.
  935: @end quotation
  936: @end cartouche
  937: 
  938: 
  939: @node $ZA
  940: @section $ZA
  941: @cindex $ZA
  942: @cindex intrinsic special variables, $ZA
  943: @cindex intrinsic special variables, implementation-specific
  944: 
  945: On the @code{HOME} device, always @code{0}. On other devices, returns the current position of the file opened on I/O channel @code{@ref{$IO}}.
  946: 
  947: @node $ZB
  948: @section $ZB
  949: @cindex $ZB
  950: @cindex intrinsic special variables, $ZB
  951: @cindex intrinsic special variables, implementation-specific
  952: 
  953: Represents the last keystroke.
  954: 
  955: @node $ZCONTROLC
  956: @section $ZCONTROLC
  957: @cindex $ZCONTROLC
  958: @cindex intrinsic special variables, $ZCONTROLC
  959: @cindex intrinsic special variables, implementation-specific
  960: 
  961: Returns the status of the Ctrl-C flag and resets it to @emph{false}.
  962: 
  963: @node $ZDATE
  964: @section $ZDATE
  965: @cindex $ZDATE
  966: @cindex intrinsic special variables, $ZDATE
  967: @cindex intrinsic special variables, implementation-specific
  968: 
  969: Returns the current date, in the preferred representation for the current system locale.
  970: 
  971: @node $ZERROR
  972: @section $ZERROR
  973: @cindex $ZERROR
  974: @cindex intrinsic special variables, $ZERROR
  975: @cindex intrinsic special variables, implementation-specific
  976: 
  977: Returns the last error message.
  978: 
  979: @node $ZHOROLOG
  980: @section $ZHOROLOG
  981: @cindex $ZHOROLOG
  982: @cindex intrinsic special variables, $ZHOROLOG
  983: @cindex intrinsic special variables, implementation-specific
  984: 
  985: Output @code{@ref{$HOROLOG}}-style time, with the addition of milliseconds.
  986: 
  987: @node $ZINRPT
  988: @section $ZINRPT
  989: @cindex $ZINRPT
  990: @cindex intrinsic special variables, $ZINRPT
  991: @cindex intrinsic special variables, implementation-specific
  992: 
  993: Gets or sets the interrupt enable/disable flag.
  994: 
  995: @node $ZJOB
  996: @section $ZJOB
  997: @cindex $ZJOB
  998: @cindex intrinsic special variables, $ZJOB
  999: @cindex intrinsic special variables, implementation-specific
 1000: 
 1001: Returns the @code{@ref{$JOB}} value of the parent process if the current process was started by a @code{@ref{JOB}} command. Otherwise, returns an empty string.
 1002: 
 1003: @node $ZLOCAL
 1004: @section $ZLOCAL
 1005: @cindex $ZLOCAL
 1006: @cindex intrinsic special variables, $ZLOCAL
 1007: @cindex intrinsic special variables, implementation-specific
 1008: 
 1009: Returns the last local variable referenced.
 1010: 
 1011: @node $ZNAME
 1012: @section $ZNAME
 1013: @cindex $ZNAME
 1014: @cindex intrinsic special variables, $ZNAME
 1015: @cindex intrinsic special variables, implementation-specific
 1016: 
 1017: Returns the name of the current routine.
 1018: 
 1019: @node $ZPRECISION
 1020: @section $ZPRECISION
 1021: @cindex $ZPRECISION
 1022: @cindex intrinsic special variables, $ZPRECISION
 1023: @cindex intrinsic special variables, implementation-specific
 1024: 
 1025: Gets or sets the number of digits of numeric precision used for fixed-point decimal arithmetic. If @code{^$JOB($JOB,"MATH")} is @code{IEEE754}, @code{$ZPRECISION} defaults to 16 digits, with a maximum of 16 digits. If @code{^$JOB($JOB,"MATH")} is @code{FIXED}, @code{$ZPRECISION} defaults to 100 digits, with a maximum of 20,000 digits.
 1026: 
 1027: @xref{^$JOB}.
 1028: 
 1029: @node $ZREFERENCE
 1030: @section $ZREFERENCE
 1031: @cindex $ZREFERENCE
 1032: @cindex intrinsic special variables, $ZREFERENCE
 1033: @cindex intrinsic special variables, implementation-specific
 1034: 
 1035: Returns the last @emph{gvn} referenced.
 1036: 
 1037: @node $ZSYSTEM
 1038: @section $ZSYSTEM
 1039: @cindex $ZSYSTEM
 1040: @cindex intrinsic special variables, $ZSYSTEM
 1041: @cindex intrinsic special variables, implementation-specific
 1042: 
 1043: Represents the return value of the last external command run with @code{!}.
 1044: 
 1045: @node $ZTIME
 1046: @section $ZTIME
 1047: @cindex $ZTIME
 1048: @cindex intrinsic special variables, $ZTIME
 1049: @cindex intrinsic special variables, implementation-specific
 1050: 
 1051: Returns the system time in the preferred representation for the current system locale.
 1052: 
 1053: @node $ZTRAP
 1054: @section $ZTRAP
 1055: @cindex $ZTRAP
 1056: @cindex intrinsic special variables, $ZTRAP
 1057: @cindex intrinsic special variables, implementation-specific
 1058: 
 1059: Sets or retrieves the entryref to be executed when an M program execution error occurs under FreeM-style or DSM 2.0-style error processing.
 1060: 
 1061: In FreeM-style error processing, @code{$ZTRAP} is specific to each program execution stack level.
 1062: 
 1063: In DSM 2.0-style error processing, @code{$ZTRAP} is the same for all program execution stack levels.
 1064: 
 1065: When FreeM encounters an error, if @code{$ZTRAP} is nonempty and @code{$ETRAP} is empty, FreeM will perform an implicit @code{@ref{GOTO}} to the entryref indicated in @code{$ZTRAP}.
 1066: 
 1067: If @code{$ETRAP} is nonempty when FreeM encounters an error, the value of @code{$ZTRAP} is ignored, whether FreeM-style or DSM 2.0-style error processing is enabled.
 1068: 
 1069: @node $ZUT
 1070: @section $ZUT
 1071: @cindex $ZUT
 1072: @cindex intrinsic special variables, $ZUT
 1073: @cindex intrinsic special variables, implementation-specific
 1074: 
 1075: Returns the number of microseconds elapsed since the UNIX epoch (Jan 1, 1970 0:00:00).
 1076: 
 1077: @node $ZVERSION
 1078: @section $ZVERSION
 1079: @cindex $ZVERSION
 1080: @cindex intrinsic special variables, $ZVERSION
 1081: @cindex intrinsic special variables, implementation-specific
 1082: 
 1083: Returns the version of FreeM in use, as well as the GNU host triplet for the current FreeM build.
 1084: 
 1085: See @emph{https://wiki.osdev.org/Target_Triplet}.
 1086: 
 1087: @node Intrinsic Functions
 1088: @chapter Intrinsic Functions
 1089: 
 1090: @menu
 1091: * $ASCII()::                            Return ASCII code for character in string.
 1092: * $CHAR()::                             Return character for one or more ASCII codes.
 1093: * $DATA()::                             Retrieve definition and characteristics of array node.
 1094: * $EXTRACT()::                          Return a substring of a string.
 1095: * $FIND()::                             Find position of substring within string.
 1096: * $FNUMBER()::                          Format a number according to formatting codes.
 1097: * $GET()::                              Return value of glvn or a default if undefined.
 1098: * $INSTANCEOF()::                       Determine if lvn is an instance of a class.
 1099: * $JUSTIFY()::                          Right-justify a string based on specified length.
 1100: * $LENGTH()::                           Return length or delimiter-based piece count of string.
 1101: * $NAME()::                             Return canonical name from string representation of glvn.
 1102: * $NEXT()::                             Return next numeric subscript following given glvn.
 1103: * $ORDER()::                            Return next subscript at same level of specified glvn.
 1104: * $PIECE()::                            Return one or more delimited pieces of a string.
 1105: * $QLENGTH()::                          Return subscript count of glvn.
 1106: * $QSUBSCRIPT()::                       Return a specified subscript from glvn.
 1107: * $QUERY()::                            Return next subscript of specified glvn.
 1108: * $RANDOM()::                           Return pseudorandom integer up to a maximum value.
 1109: * $REVERSE()::                          Reverse a string.
 1110: * $SELECT()::                           Return value from first true condition in list of expressions.
 1111: * $STACK()::                            Return information about the program stack.
 1112: * $TEXT()::                             Return line of code from a routine.
 1113: * $TRANSLATE()::                        Substitute specified characters in a string.
 1114: * $TYPE()::                             Return class of the specified lvn.
 1115: * $VIEW()::                             Retrieve implementation-specific information.
 1116: * $ZBOOLEAN()::                         Perform boolean operations on numeric arguments.
 1117: * $ZCALL()::                            Unknown.
 1118: * $ZCRC()::                             Generate checksum of a string argument.
 1119: * $ZDATA()::                            Unknown.
 1120: * $ZDATE()::                            Convert @code{@ref{$HOROLOG}} string into human-readable date.
 1121: * $ZEDIT()::                            Unknown.
 1122: * $ZHOROLOG()::                         Convert date/time values to @code{@ref{$HOROLOG}} format.
 1123: * $ZKEY()::                             Unknown.
 1124: * $ZLENGTH()::                          Unknown.
 1125: * $ZLSD()::                             Compute Levenshtein distance between two arguments.
 1126: * $ZM()::                               Unknown.
 1127: * $ZNAME()::                            Unknown.
 1128: * $ZNEXT()::                            Return glvn of next numeric subscript following given glvn.
 1129: * $ZORDER()::                           Unknown.
 1130: * $ZPIECE()::                           Unknown.
 1131: * $ZPREVIOUS()::                        Unknown.
 1132: * $ZREPLACE()::                         Replace all instances of a substring within a string.
 1133: * $ZSYNTAX()::                          Perform syntax check on string argument.
 1134: * $ZTIME()::                            Convert a @code{@ref{$HOROLOG}} string into human-readable time.
 1135: @end menu
 1136: 
 1137: @node $ASCII()
 1138: @section $ASCII
 1139: @cindex $ASCII
 1140: @cindex intrinsic functions, $ASCII
 1141: 
 1142: Returns the ASCII code (in decimal) for one character in a string.
 1143: 
 1144: @example
 1145: SET RESULT=$ASCII(@emph{<string>}[,@emph{<index>}])
 1146: @end example
 1147: 
 1148: 
 1149: If @emph{<index>} is not supplied, @code{$ASCII} will return the ASCII code of the first character. Otherwise, returns the ASCII code of the character at position @emph{<index>}.
 1150: 
 1151: @node $CHAR()
 1152: @section $CHAR
 1153: @cindex $CHAR
 1154: @cindex intrinsic functions, $CHAR
 1155: 
 1156: Returns a string of characters corresponding to a list of ASCII codes.
 1157: 
 1158: @example
 1159: SET RESULT=$CHAR(@emph{<ascii-code>}[,@emph{<ascii-code>},...])
 1160: @end example
 1161: 
 1162: @node $DATA()
 1163: @section $DATA
 1164: @cindex $DATA
 1165: @cindex intrinsic functions, $DATA
 1166: 
 1167: Returns a numeric value 0, 1, 10, or 11, depending on whether a referenced node is defined, has data, or has children:
 1168: 
 1169: @example
 1170: SET RESULT=$DATA(@emph{<node>})
 1171: @end example
 1172: 
 1173: The return values are as follows:
 1174: 
 1175: @example
 1176: 0: @emph{<node>} is undefined
 1177: 1: @emph{<node>} has data but no children
 1178: 10: @emph{<node>} has children but no data
 1179: 11: @emph{<node>} has children and data
 1180: @end example
 1181: 
 1182: @node $EXTRACT()
 1183: @section $EXTRACT
 1184: @cindex $EXTRACT
 1185: @cindex intrinsic functions, $EXTRACT
 1186: 
 1187: Extracts a substring of a string.
 1188: 
 1189: The first argument is the source string.
 1190: 
 1191: The optional second argument specifies the starting position of the substring to extract, and defaults to @code{1}.
 1192: 
 1193: The optional third argument specifies the ending position of the substring to extract, and defaults to the value of the second argument, or @code{1}.
 1194: 
 1195: This example will extract the string @emph{FreeM} into the local variable @code{M}.
 1196: 
 1197: @example
 1198: SET NAME="FreeM is the best!"
 1199: SET M=$EXTRACT(NAME,1,5)
 1200: @end example
 1201: 
 1202: It is also possible to use @code{$EXTRACT} on the left-hand side of a @code{SET} assignment in order to modify a substring:
 1203: 
 1204: @example
 1205: DEFAULT.USER> SET FOO="ABCDEFG"
 1206: 
 1207: 
 1208: DEFAULT.USER> SET $EXTRACT(FOO,1,3)="XYZ"
 1209: 
 1210: 
 1211: DEFAULT.USER> WRITE FOO
 1212: 
 1213: XYZDEFG
 1214: @end example
 1215: 
 1216: @node $FIND()
 1217: @section $FIND
 1218: @cindex $FIND
 1219: @cindex intrinsic functions, $FIND
 1220: 
 1221: Finds the character immediately following the first occurence of a substring within a string.
 1222: 
 1223: The first argument is the source string.
 1224: 
 1225: The second argument is the substring to be located.
 1226: 
 1227: The optional third argument indicates the position within the source string at which to begin searching.
 1228: 
 1229: @node $FNUMBER()
 1230: @section $FNUMBER
 1231: @cindex $FNUMBER
 1232: @cindex intrinsic functions, $FNUMBER
 1233: 
 1234: Formats a number according to a particular set of formatting codes.
 1235: 
 1236: The first argument is the number to format.
 1237: 
 1238: The second argument is the series of formatting codes:
 1239: 
 1240: @table @asis
 1241: @item 'P' or 'p'
 1242: Will display negative numbers within parentheses instead of showing a minus sign.
 1243: @item , (comma)
 1244: Will add commas as thousands separators.
 1245: @item +
 1246: Will include a plus sign for positive numbers. Not compatible with 'P' or 'p'.
 1247: @item -
 1248: Will remove the minus sign from negative numbers. Not compatible with 'p' or 'P'.
 1249: @item 't' or 'T'
 1250: Will place the sign after the number instead of before the number.
 1251: @end table
 1252: 
 1253: The optional third argument is a number indicating how many digits to which the fractional part of the number will be zero-padded.
 1254: 
 1255: @node $GET()
 1256: @section $GET
 1257: @cindex $GET
 1258: @cindex intrinsic functions, $GET
 1259: 
 1260: Returns the value of a local, global, or SSVN if the specified item is defined, or a default value otherwise.
 1261: 
 1262: The first argument is the local, global, or SSVN to be examined.
 1263: 
 1264: The optional second argument is the default value to be returned if the referenced item is undefined, and defaults to the empty string.
 1265: 
 1266: @node $INSTANCEOF()
 1267: @section $INSTANCEOF
 1268: @cindex $INSTANCEOF
 1269: @cindex intrinsic functions, $INSTANCEOF
 1270: @cindex object functions, $INSTANCEOF
 1271: 
 1272: Returns @code{1} if the specified @emph{lvn} is an instance of class @emph{class}, or @code{0} otherwise.
 1273: 
 1274: The first argument is a string representing a valid FreeM local variable.
 1275: 
 1276: The second argument is a string representing a valid FreeM class.
 1277: 
 1278: @example
 1279: DEFAULT.USER> N STR=$$^%STRING
 1280: 
 1281: DEFAULT.USER> W $INSTANCEOF("STR","^%STRING")
 1282: 1
 1283: @end example
 1284: 
 1285: @node $JUSTIFY()
 1286: @section $JUSTIFY
 1287: @cindex $JUSTIFY
 1288: @cindex intrinsic functions, $JUSTIFY
 1289: 
 1290: Right-justifies a string based on a specified fixed length.
 1291: 
 1292: The first argument is the source string.
 1293: 
 1294: The second argument is the character length of the output.
 1295: 
 1296: The optional third argument controls the number of fractional digits to be included in the output, and defaults to the number of digits specified in the first argument.
 1297: 
 1298: @node $LENGTH()
 1299: @section $LENGTH
 1300: @cindex $LENGTH
 1301: @cindex intrinsic functions, $LENGTH
 1302: 
 1303: Returns the length of a string, or the number of items in a list delimited by a specified character (as used by @code{@ref{$PIECE()}}).
 1304: 
 1305: The first argument is the source string.
 1306: 
 1307: The optional second argument is the list delimiter to be used. When this argument is omitted, the length of the string in characters is returned.
 1308: 
 1309: @node $NAME()
 1310: @section $NAME
 1311: @cindex $NAME
 1312: @cindex intrinsic functions, $NAME
 1313: 
 1314: Returns the canonical name reference along with some or all of its subscripts.
 1315: 
 1316: The first argument is the source name.
 1317: 
 1318: The optional second argument indicates the maximum subscript count to be returned, and defaults to the subscript count of the source name.
 1319: 
 1320: @node $NEXT()
 1321: @section $NEXT
 1322: @cindex $NEXT
 1323: @cindex intrinsic functions, $NEXT
 1324: 
 1325: Deprecated. Use @code{$ORDER} instead.
 1326: Returns the next numeric subscript of the specified glvn.
 1327: 
 1328: @emph{Syntax}
 1329: 
 1330: @example
 1331: $NEXT(@emph{glvn})
 1332: @end example
 1333: 
 1334: @emph{Example}
 1335: 
 1336: Assume the following array:
 1337: 
 1338: @example
 1339: ^foo(1)=""
 1340: ^foo(2)=""
 1341: @end example
 1342: 
 1343: And the following code:
 1344: 
 1345: @example
 1346:  W $ZNEXT(^foo(1)) ; => 2
 1347: @end example 
 1348: 
 1349: @node $ORDER()
 1350: @section $ORDER
 1351: @cindex $ORDER
 1352: @cindex intrinsic functions, $ORDER
 1353: 
 1354: Returns the previous subscript or next subscript in a local, global, or a subset of structured system variables.
 1355: 
 1356: The first argument is the subscripted local, global, or SSVN.
 1357: 
 1358: The optional second argument can be @code{1} to retrieve the next subscript, or @code{-1} to return the previous.
 1359: 
 1360: @node $PIECE()
 1361: @section $PIECE
 1362: @cindex $PIECE
 1363: @cindex intrinsic functions, $PIECE
 1364: 
 1365: @emph{Syntax}
 1366: 
 1367: @code{$PIECE(@emph{s},@emph{d}[,@emph{n}[,@emph{end}]])}
 1368: 
 1369: Accesses the @code{n}th through @code{end} @code{d}-delimited pieces of string @code{s}.
 1370: 
 1371: The first argument is the string to be evaluated.
 1372: 
 1373: The second argument is the delimiter to be used.
 1374: 
 1375: The optional third argument is the first @code{d}-delimited piece to access, and defaults to @code{1}.
 1376: 
 1377: The optional fourth argument is the final @code{d}-delimited piece to access, and defaults to the value of the third argument (@code{n}).
 1378: 
 1379: Can be used on the left-hand side of an expression in order to @code{@ref{SET}} a value into a @code{d}-delimited piece of @code{s}, as in:
 1380: 
 1381: @example
 1382: ; ^snw="this^is^a^piece"
 1383: SET $PIECE(^snw,"^",2)="isn't" ; => "this^isn't^a^piece"
 1384: @end example
 1385: 
 1386: @node $QLENGTH()
 1387: @section $QLENGTH
 1388: @cindex $QLENGTH
 1389: @cindex intrinsic functions, $QLENGTH
 1390: 
 1391: @emph{Syntax}
 1392: 
 1393: @example
 1394: @code{$QLENGTH(@emph{expr V glvn})}
 1395: @end example
 1396: 
 1397: Returns the number of subscripts in @emph{glvn}.
 1398: 
 1399: @emph{Example}
 1400: @example
 1401: @code{SET SUBCT=$QLENGTH("^GBL(1,2,3)") ; => 3}
 1402: @end example
 1403: 
 1404: @node $QSUBSCRIPT()
 1405: @section $QSUBSCRIPT
 1406: @cindex $QSUBSCRIPT
 1407: @cindex intrinsic functions, $QSUBSCRIPT
 1408: 
 1409: @emph{Syntax}
 1410: 
 1411: @example
 1412: @code{$QSUBSCRIPT(@emph{expr V glvn},@emph{expr V n})}
 1413: @end example
 1414: 
 1415: In the RHS form, returns the @emph{n}th subscript of @emph{glvn}.
 1416: 
 1417: @emph{Example}
 1418: 
 1419: @example
 1420: @code{SET SUB=$QSUBSCRIPT("^GBL(1,2,3)",2) ; => 2}
 1421: @end example
 1422: 
 1423: @emph{Syntax}
 1424: 
 1425: @example
 1426: @code{SET $QSUBSCRIPT(@emph{expr V glvn},@emph{expr V n})=@emph{expr} ; => ^GBL(1,4,3)}
 1427: @end example
 1428: 
 1429: In the LHS form, sets the @emph{n}th subscript of @emph{glvn} to @emph{expr}.
 1430: 
 1431: @node $QUERY()
 1432: @section $QUERY
 1433: @cindex $QUERY
 1434: @cindex intrinsic functions, $QUERY
 1435: 
 1436: Returns the next subscripted reference in a global.
 1437: 
 1438: @emph{Syntax}
 1439: 
 1440: @example
 1441: @code{$QUERY(@emph{glvn})}
 1442: @end example
 1443: 
 1444: @emph{Example}
 1445: 
 1446: We will assume the following data structure exists:
 1447: @example
 1448: ^snw(1)=1
 1449: ^snw(1,2)="foo"
 1450: ^snw(2)=3
 1451: ^snw(3)=""
 1452: @end example
 1453: 
 1454: The following code will retrieve the next subscripted name after @code{^snw(1)}:
 1455: 
 1456: @example
 1457: @code{SET NEXTNAM=$QUERY(^snw(1)) ; => ^snw(1,2)}
 1458: @end example
 1459: 
 1460: @node $RANDOM()
 1461: @section $RANDOM
 1462: @cindex $RANDOM
 1463: @cindex intrinsic functions, $RANDOM
 1464: 
 1465: @emph{Syntax}
 1466: 
 1467: @example
 1468: $RANDOM(@emph{max})
 1469: @end example
 1470: 
 1471: Returns a pseudo-random integer in the range of @code{0..@emph{max} - 1} 
 1472: 
 1473: @node $REVERSE()
 1474: @section $REVERSE
 1475: @cindex $REVERSE
 1476: @cindex intrinsic functions, $REVERSE
 1477: 
 1478: @emph{Syntax}
 1479: 
 1480: @example
 1481: $REVERSE(@emph{s})
 1482: @end example
 1483: 
 1484: Returns the reverse of string @emph{s}.
 1485: 
 1486: @emph{Example}
 1487: 
 1488: @example
 1489: SET FOO=$REVERSE("ABC") ; => CBA
 1490: @end example
 1491: 
 1492: @node $SELECT()
 1493: @section $SELECT
 1494: @cindex $SELECT
 1495: @cindex intrinsic functions, $SELECT
 1496: 
 1497: Returns a value corresponding to the first true condition in a list of conditional expressions. Each argument is an expression, followed by a colon, followed by an expression whose value will be returned if the first expression is true. If no expressions are true, error condition @code{M4} is raised.
 1498: 
 1499: @emph{Example}
 1500: 
 1501: @example
 1502: SET FOO=$SELECT(1=2:"math is broken",1=1:"the world makes sense") ; => "the world makes sense"
 1503: @end example
 1504: 
 1505: @node $STACK()
 1506: @section $STACK
 1507: @cindex $STACK
 1508: @cindex intrinsic functions, $STACK
 1509: 
 1510: Returns information about the program execution stack. The @code{$STACK} intrinsic function has both a one-argument form and a two-argument form.
 1511: 
 1512: @emph{Syntax (One-Argument)}
 1513: 
 1514: @example
 1515:  $STACK(@emph{<num>})
 1516: @end example
 1517: 
 1518: If @emph{num} is @code{0}, returns the command with which this FreeM instance was invoked.
 1519: 
 1520: If @emph{num} is @code{-1}, returns the current program execution stack level.
 1521: 
 1522: If @emph{num} represents a valid program execution stack depth above @code{0}, returns one of the following values indicating the reason for which the referenced program execution stack level was created:
 1523: 
 1524: @table @asis
 1525: 
 1526: @item @code{$$}
 1527: If @code{$STACK(@emph{<num>})="$$"}, program execution stack level @code{num} was created as the result of an extrinsic function call
 1528: 
 1529: @item @emph{<m-command>}
 1530: If @code{$STACK(@emph{<num>})} returns a valid M command, the referenced program execution stack level was created as a result of the @emph{m-command} command.
 1531: 
 1532: @end table
 1533: 
 1534: @emph{Syntax (Two-Argument})
 1535: 
 1536: @example
 1537:  $STACK(@emph{<num>},"[ECODE|MCODE|PLACE]")
 1538: @end example
 1539: 
 1540: Returns the error codes, M program code, or entryref applicable to the action that created program execution stack level @emph{num}.
 1541: 
 1542: @node $TEXT()
 1543: @section $TEXT
 1544: @cindex $TEXT
 1545: @cindex intrinsic functions, $TEXT
 1546: 
 1547: Returns a line of code from a routine.
 1548: 
 1549: @node $TRANSLATE()
 1550: @section $TRANSLATE
 1551: @cindex $TRANSLATE
 1552: @cindex intrinsic functions, $TRANSLATE
 1553: 
 1554: Replaces characters in a string.
 1555: 
 1556: The first argument is a string expression representing the text to be changed.
 1557: 
 1558: The second argument is a list of characters to replace.
 1559: 
 1560: The third argument is a list of characters to use as the replacements for the characters in the second argument.
 1561: 
 1562: @emph{Example}
 1563: 
 1564: @example
 1565:  DEFAULT.USER> W $TRANSLATE("twig","wt","rb")
 1566:  brig
 1567: @end example
 1568: 
 1569: @node $TYPE()
 1570: @section $TYPE
 1571: @cindex $TYPE
 1572: @cindex intrinsic functions, $TYPE
 1573: @cindex object functions, $TYPE
 1574: 
 1575: Returns a string giving the class of the object specified in the parameter.
 1576: 
 1577: @xref{Object-Oriented Programming}
 1578: 
 1579: @node $VIEW()
 1580: @section $VIEW
 1581: @cindex $VIEW
 1582: @cindex intrinsic functions, $VIEW
 1583: 
 1584: @node $ZBOOLEAN()
 1585: @section $ZBOOLEAN
 1586: @cindex $ZBOOLEAN
 1587: @cindex intrinsic functions, $ZBOOLEAN
 1588: @cindex intrinsic functions, implementation-specific
 1589: 
 1590: 
 1591: Performs @emph{boolean-operation} on numeric arguments @emph{A} and @emph{B}.
 1592: 
 1593: @emph{Syntax}
 1594: 
 1595: @example
 1596: SET RESULT=$ZBOOLEAN(@emph{A},@emph{B},@emph{boolean-operation})
 1597: @end example
 1598: 
 1599: @code{$ZBOOLEAN} Operations (@emph{boolean-operation} values)
 1600: 
 1601: @table @code
 1602: @item 0
 1603: Always @emph{false}
 1604: @item 1
 1605: @code{A AND B}
 1606: @item 2
 1607: @code{A AND NOT B}
 1608: @item 3
 1609: @code{A}
 1610: @item 4
 1611: @code{NOT A AND B}
 1612: @item 5
 1613: @code{B}
 1614: @item 6
 1615: @code{A XOR B}
 1616: @item 7
 1617: @code{A OR B}
 1618: @item 8
 1619: @code{A NOR B}
 1620: @item 9
 1621: @code{A EQUALS B}
 1622: @item 10
 1623: @code{NOT B}
 1624: @item 11
 1625: @code{A OR NOT B}
 1626: @item 12
 1627: @code{NOT A}
 1628: @item 13
 1629: @code{NOT A OR B}
 1630: @item 14
 1631: @code{A NAND B}
 1632: @item 15
 1633: Always @emph{true}
 1634: @end table
 1635: 
 1636: @node $ZCALL()
 1637: @section $ZCALL
 1638: @cindex $ZCALL
 1639: @cindex intrinsic functions, $ZCALL
 1640: @cindex intrinsic functions, implementation-specific
 1641: 
 1642: Purpose unknown.
 1643: 
 1644: @node $ZCRC()
 1645: @section $ZCRC
 1646: @cindex $ZCRC
 1647: @cindex intrinsic functions, $ZCRC
 1648: @cindex intrinsic functions, implementation-specific
 1649: 
 1650: Returns a checksum of @code{arg1}.
 1651: 
 1652: @emph{Syntax}
 1653: 
 1654: @code{$ZCRC(@emph{arg1})}
 1655: 
 1656: @code{SET VAR=$ZCRC("MUMPS") ; => 86}
 1657: 
 1658: @node $ZDATA()
 1659: @section $ZDATA
 1660: @cindex $ZDATA
 1661: @cindex intrinsic functions, $ZDATA
 1662: @cindex intrinsic functions, implementation-specific
 1663: 
 1664: Purpose unknown.
 1665: 
 1666: @node $ZDATE()
 1667: @section $ZDATE
 1668: @cindex $ZDATE
 1669: @cindex intrinsic functions, $ZDATE
 1670: @cindex intrinsic functions, implementation-specific
 1671: 
 1672: Converts a @code{@ref{$HOROLOG}} string into a human-readable date.
 1673: 
 1674: @emph{Syntax}
 1675: 
 1676: @example
 1677: SET VAR=$ZDATE($H[,@emph{<format-string>}])
 1678: @end example
 1679: 
 1680: The optional @emph{<format-string>} follows the same rules as the UNIX @code{strftime} function. If @emph{<format-string>} is omitted, the value of @code{^$SYSTEM("ZDATE_FORMAT")} is used (typically @code{%x}).
 1681: 
 1682: @xref{^$SYSTEM}
 1683: 
 1684: @node $ZEDIT()
 1685: @section $ZEDIT
 1686: @cindex $ZEDIT
 1687: @cindex intrinsic functions, $ZEDIT
 1688: @cindex intrinsic functions, implementation-specific
 1689: 
 1690: Purpose unknown.
 1691: 
 1692: @node $ZHOROLOG()
 1693: @section $ZHOROLOG
 1694: @cindex $ZHOROLOG
 1695: @cindex intrinsic functions, $ZHOROLOG
 1696: @cindex intrinsic functions, implementation-specific
 1697: 
 1698: Converts date and/or time values producible by @code{@ref{$ZDATE()}} or @code{@ref{$ZTIME()}} to @code{@ref{$HOROLOG}} format.
 1699: 
 1700: @emph{Syntax}
 1701: 
 1702: @example
 1703: $ZHOROLOG(@emph{<date-value>},@emph{<format-string>})
 1704: @end example
 1705: 
 1706: @emph{<date-value>} is a date or time string compatible with the formats from @code{@ref{$ZDATE()}} or @code{@ref{$ZTIME}}.
 1707: 
 1708: @emph{<format-string>} is a format string of the same format as used by the @code{strptime(3)} UNIX function.
 1709: 
 1710: @node $ZKEY()
 1711: @section $ZKEY
 1712: @cindex $ZKEY
 1713: @cindex intrinsic functions, $ZKEY
 1714: @cindex intrinsic functions, implementation-specific
 1715: 
 1716: Purpose unknown.
 1717: 
 1718: @node $ZLENGTH()
 1719: @section $ZLENGTH
 1720: @cindex $ZLENGTH
 1721: @cindex intrinsic functions, $ZLENGTH
 1722: @cindex intrinsic functions, implementation-specific
 1723: 
 1724: Purpose unknown.
 1725: 
 1726: @node $ZLSD()
 1727: @section $ZLSD
 1728: @cindex $ZLSD
 1729: @cindex intrinsic functions, $ZLSD
 1730: @cindex intrinsic functions, implementation-specific
 1731: 
 1732: Returns the Levenshtein distance between two arguments. The Levenshtein distance represents the minimum number of edits needed to change the first argument into the second argument.
 1733: 
 1734: @emph{Syntax}
 1735: 
 1736: @code{SET VAR=$ZLSD(@emph{arg1},@emph{arg2})}
 1737: 
 1738: @emph{Example}
 1739: 
 1740: @code{SET VAR=$ZLSD("KITTENS","MITTENS") ; => 1}
 1741: 
 1742: @node $ZM()
 1743: @section $ZM
 1744: @cindex $ZM
 1745: @cindex intrinsic functions, $ZM
 1746: @cindex intrinsic functions, implementation-specific
 1747: 
 1748: Purpose unknown.
 1749: 
 1750: @node $ZNAME()
 1751: @section $ZNAME
 1752: @cindex $ZNAME
 1753: @cindex intrinsic functions, $ZNAME
 1754: @cindex intrinsic functions, implementation-specific
 1755: 
 1756: Purpose unknown.
 1757: 
 1758: This function relies on the value of @code{$VIEW(71)} being @code{0} (this is not the default).
 1759: 
 1760: @node $ZNEXT()
 1761: @section $ZNEXT
 1762: @cindex $ZNEXT
 1763: @cindex intrinsic functions, $ZNEXT
 1764: @cindex intrinsic functions, implementation-specific
 1765: 
 1766: Returns a fully-formed variable reference of the next numeric subscript of the specified glvn.
 1767: 
 1768: @emph{Syntax}
 1769: 
 1770: @example
 1771: $ZNEXT(@emph{glvn})
 1772: @end example
 1773: 
 1774: @emph{Example}
 1775: 
 1776: Assume the following array:
 1777: 
 1778: @example
 1779: ^foo(1)=""
 1780: ^foo(2)=""
 1781: @end example
 1782: 
 1783: And the following code:
 1784: 
 1785: @example
 1786:  W $ZNEXT(^foo(1)) ; => ^foo(2)
 1787: @end example
 1788: 
 1789: This function relies on the value of @code{$VIEW(71)} being @code{1} (this is the default).
 1790: 
 1791: @node $ZORDER()
 1792: @section $ZORDER
 1793: @cindex $ZORDER
 1794: @cindex intrinsic functions, $ZORDER
 1795: @cindex intrinsic functions, implementation-specific
 1796: 
 1797: Purpose unknown.
 1798: 
 1799: @node $ZPIECE()
 1800: @section $ZPIECE
 1801: @cindex $ZPIECE
 1802: @cindex intrinsic functions, $ZPIECE
 1803: @cindex intrinsic functions, implementation-specific
 1804: 
 1805: Purpose unknown.
 1806: 
 1807: @node $ZPREVIOUS()
 1808: @section $ZPREVIOUS
 1809: @cindex $ZPREVIOUS
 1810: @cindex intrinsic functions, $ZPREVIOUS
 1811: @cindex intrinsic functions, implementation-specific
 1812: 
 1813: Purpose unknown.
 1814: 
 1815: @node $ZREPLACE()
 1816: @section $ZREPLACE
 1817: @cindex $ZREPLACE
 1818: @cindex intrinsic functions, $ZREPLACE
 1819: @cindex intrinsic functions, implementation-specific
 1820: 
 1821: Replaces all instances of @code{arg2} with @code{arg3} in string @code{arg1}.
 1822: 
 1823: @emph{Syntax}
 1824: @code{$ZREPLACE(@emph{arg1},@emph{arg2},@emph{arg3})}
 1825: 
 1826: @emph{Example}
 1827: 
 1828: @code{SET VAR=$ZREPLACE("CAT","C","B") ; => BAT}
 1829: 
 1830: @node $ZSYNTAX()
 1831: @section $ZSYNTAX
 1832: @cindex $ZSYNTAX
 1833: @cindex intrinsic functions, $ZSYNTAX
 1834: @cindex intrinsic functions, implementation-specific
 1835: 
 1836: @code{$ZSYNTAX} performs a very basic syntax check on @emph{expr V mcode}. Checks only for illegal commands, mismatched brackets, mismatched quotes, missing or surplus arguments, or surplus commas.
 1837: 
 1838: @emph{Syntax}
 1839: @example
 1840: $ZSYNTAX(@emph{expr V mcode})
 1841: @end example
 1842: 
 1843: If no syntax error is found, returns the empty string.
 1844: 
 1845: If a syntax error is found, returns a number indicating the position in @emph{expr V mcode} at which the error was found, followed by a comma, and the FreeM error code that was found.
 1846: 
 1847: @node $ZTIME()
 1848: @section $ZTIME
 1849: @cindex $ZTIME
 1850: @cindex intrinsic functions, $ZTIME
 1851: @cindex intrinsic functions, implementation-specific
 1852: 
 1853: Converts a @code{@ref{$HOROLOG}} string into a human-readable time.
 1854: 
 1855: @emph{Syntax}
 1856: 
 1857: @example
 1858: SET VAR=$ZTIME($H[,@emph{<format-string>}])
 1859: @end example
 1860: 
 1861: The optional @emph{<format-string>} follows the same rules as the UNIX @code{strftime(3)} function. If @emph{<format-string>} is omitted, the value of @code{^$SYSTEM("ZTIME_FORMAT")} is used (typically @code{%X}).
 1862: 
 1863: @node OBJECT Methods
 1864: @chapter OBJECT Methods
 1865: 
 1866: These methods are part of the @code{^%OBJECT} class, from which all FreeM objects ultimately inherit.
 1867: 
 1868: Please note that classes may override @code{^%OBJECT} methods (or methods of any class) in order to provide results more fitting to the class's abstraction goals.
 1869: 
 1870: @menu
 1871: * $$TONUMBER::          Returns the canonical numeric representation of the object.
 1872: * $$TYPE::              Returns the fully-qualified class name of the object.
 1873: * $$VALUE::             Returns the value of the object.
 1874: @end menu
 1875: 
 1876: @node $$TONUMBER
 1877: @section $$TONUMBER
 1878: 
 1879: Returns (when applicable) a canonical numeric representation of the referenced object.
 1880: 
 1881: @emph{Syntax}
 1882: 
 1883: @example
 1884: W $$MYOBJECT.TONUMBER(),!
 1885: @end example
 1886: 
 1887: If no canonical numeric representation of the object is possible, will return the empty string.
 1888: 
 1889: @node $$TYPE
 1890: @section $$TYPE
 1891: 
 1892: Returns the fully-qualified class of the referenced object.
 1893: 
 1894: @emph{Syntax}
 1895: 
 1896: @example
 1897: W $$MYOBJECT.TYPE()
 1898: @end example
 1899: 
 1900: Note that M variables that are created by non-object-oriented means will be objects of the @code{^%STRING} class.
 1901: 
 1902: @node $$VALUE
 1903: @section $$VALUE
 1904: 
 1905: Returns the value of the referenced object.
 1906: 
 1907: @emph{Syntax}
 1908: 
 1909: @example
 1910: W $$MYOBJECT.VALUE()
 1911: @end example
 1912: 
 1913: @node STRING Methods
 1914: @chapter STRING Methods
 1915: 
 1916: These are methods inherent to the @code{^%STRING} class, which is the default class for M variables created without specifying a class.
 1917: 
 1918: @menu
 1919: * $$ASCII::             Return the ASCII code of a character within the string.
 1920: * $$DATA::              Return tree characteristics of the string.
 1921: * $$DISTANCE::          Determine Levenstein distance between this string and another.
 1922: * $$EXTRACT::           Return a substring of the string.
 1923: * $$FIND::              Find the position of a substring within the string.
 1924: * $$FNUMBER::           Format numbers.
 1925: * $$JUSTIFY::           Pad the string to specific positions.
 1926: * $$LENGTH::            Return the length of the string.
 1927: * $$PIECECOUNT::        Return the count of pieces existing between instances of a delimiter.
 1928: * $$PIECE::             Return a delimited subset of the string.
 1929: * $$REPLACE::           Replace instances of a substring within the string.
 1930: * $$REVERSE::           Reverse the order of characters in the string.
 1931: * $$TOLOWER::           Return a lowercase version of the string.
 1932: * $$TOUPPER::           Return an uppercase version of the string.
 1933: * $$TRANSLATE::         Replace individual characters within the string.
 1934: @end menu
 1935: 
 1936: @node $$ASCII
 1937: @section $$ASCII
 1938: 
 1939: Returns the ASCII code of a character within the string. See @ref{$ASCII()}.
 1940: 
 1941: @emph{Syntax}
 1942: 
 1943: @example
 1944: W $$MYOBJECT.ASCII(3)
 1945: @end example
 1946: 
 1947: The above example returns the ASCII code in position 3 of string object @code{MYOBJECT}.
 1948: 
 1949: @node $$DATA
 1950: @section $$DATA
 1951: 
 1952: Returns the value of the @code{$DATA} intrinsic function as performed on the value of the object. See @ref{$DATA()}.
 1953: 
 1954: @emph{Syntax}
 1955: 
 1956: @example
 1957: W $$MYOBJECT.DATA()
 1958: @end example
 1959: 
 1960: @node $$DISTANCE
 1961: @section $$DISTANCE
 1962: 
 1963: Returns the Levenstein distance between the string and another string. See @ref{$ZLSD()}.
 1964: 
 1965: @emph{Syntax}
 1966: 
 1967: @example
 1968: W $$MYOBJECT.DISTANCE("someString")
 1969: @end example
 1970: 
 1971: @node $$EXTRACT
 1972: @section $$EXTRACT
 1973: 
 1974: Returns a substring of the string. See @ref{$EXTRACT()}.
 1975: 
 1976: @emph{Syntax}
 1977: 
 1978: @example
 1979: $$<objectName>.EXTRACT(<start>,<end>)
 1980: @end example
 1981: 
 1982: 
 1983: @node $$FIND
 1984: @section $$FIND
 1985: 
 1986: Finds the character immediately following the first occurence of a substring within a string.
 1987: 
 1988: The first argument is the substring to be located.
 1989: 
 1990: The second argument is the position within the string at which to begin searching.
 1991: 
 1992: See @ref{$FIND()}.
 1993: 
 1994: @node $$FNUMBER
 1995: @section $$FNUMBER
 1996: 
 1997: Formats a number according to a set of formatting codes.
 1998: 
 1999: The argument is a series of formatting codes. See @ref{$FNUMBER()} for details.
 2000: 
 2001: @node $$JUSTIFY
 2002: @section $$JUSTIFY
 2003: 
 2004: Right-justifies a string based on a specified fixed length.
 2005: 
 2006: The first argument is the character length of the output.
 2007: 
 2008: The second argument controls the number of fractional digits to be included in the output, and defaults to the number of digits specified in the first argument.
 2009: 
 2010: See @ref{$JUSTIFY()} for details.
 2011: 
 2012: @node $$LENGTH
 2013: @section $$LENGTH
 2014: 
 2015: Returns the length of the string.
 2016: 
 2017: @node $$PIECECOUNT
 2018: @section $$PIECECOUNT
 2019: 
 2020: Returns the number of items in a list delimited by the character specified in the argument.
 2021: 
 2022: @node $$PIECE
 2023: @section $$PIECE
 2024: 
 2025: @emph{Syntax}
 2026: 
 2027: @code{$PIECE(@emph{d}[,@emph{n}[,@emph{end}]])}
 2028: 
 2029: Accesses the @code{n}th through @code{end} @code{d}-delimited pieces of the string.
 2030: 
 2031: The first argument is the delimiter to be used.
 2032: 
 2033: The optional second argument is the first @code{d}-delimited piece to access, and defaults to @code{1}.
 2034: 
 2035: The optional third argument is the final @code{d}-delimited piece to access, and defaults to the value of the third argument (@code{n}).
 2036: 
 2037: 
 2038: @node $$REPLACE
 2039: @section $$REPLACE
 2040: 
 2041: @emph{Syntax}
 2042: @code{myString.$$REPLACE(@emph{arg1},@emph{arg2})}
 2043: 
 2044: Replaces all instances of @code{arg2} with @code{arg3} in @code{myString}.
 2045: 
 2046: @node $$REVERSE
 2047: @section $$REVERSE
 2048: 
 2049: Returns the reverse of the string.
 2050: 
 2051: @node $$TOLOWER
 2052: @section $$TOLOWER
 2053: 
 2054: Returns an all-lowercase version of the string.
 2055: 
 2056: @node $$TOUPPER
 2057: @section $$TOUPPER
 2058: 
 2059: Returns an all-uppercase version of the string.
 2060: 
 2061: @node $$TRANSLATE
 2062: @section $$TRANSLATE
 2063: 
 2064: Identical to @ref{$TRANSLATE()}, except that the arguments are shifted left by one, and the input string is implicit (the object).
 2065: 
 2066: @node Commands
 2067: @chapter Commands
 2068: @cindex commands
 2069: 
 2070: @menu
 2071: * @@::                                  Execute the following expression as M code.
 2072: * !::                                   Run an external program or command.
 2073: * !!::                                  Launch a subshell from FreeM direct mode.
 2074: * ABLOCK::                              Increment the block counter for one or more event classes.
 2075: * ASTART::                              Enable asynchronous event handling for one or more event classes.
 2076: * ASTOP::                               Disable asynchronous event handling for one or more event classes.
 2077: * AUNBLOCK::                            Decrement the block counter for one or more event classes.
 2078: * BREAK::                               Interrupt a running routine to allow interactive debugging.
 2079: * CLOSE::                               Close an input/output device.
 2080: * DO::                                  Transfer program control to one or more subroutines or introduces a new execution level.
 2081: * ELSE::                                Execute the remainder of a line if @code{@ref{$TEST}} evaluates @emph{false}.
 2082: * FOR::                                 Repeat execution of a line or block of code.
 2083: * GOTO::                                Unconditionally transfer program execution to a supplied @emph{entryref}.
 2084: * HALT::                                Terminate the current FreeM interpreter instance.
 2085: * HANG::                                Temporarily suspend the running program.
 2086: * IF::                                  Execute the remainder of a line if a conditional expression evaluates @emph{true}.
 2087: * JOB::                                 Execute an @emph{entryref} in a child process.
 2088: * KILL::                                Remove data from a local, global, or structured system variable.
 2089: * KSUBSCRIPTS::                         Kill only the descendant subscripts of a local, global, global, or structured system variable.
 2090: * KVALUE::                              Kill only the value of a local, global, or structured system variable.
 2091: * LOCK::                                Control advisory locking for concurrency control.
 2092: * MERGE::                               Merge contents of one local, global, or structured system variable into another.
 2093: * NEW::                                 Introduce a new scope for a specified local variable or intrinsic special variable or instantiate an object.
 2094: * OPEN::                                Open a sequential or socket input/output device.
 2095: * QUIT::                                End execution of the current process level, optionally with return value.
 2096: * READ::                                Read input from an input/output device.
 2097: * SET::                                 Set the value of a local variable, global, intrinsic special variable, or structured system variable.
 2098: * TCOMMIT::                             Commit a transaction.
 2099: * THEN::                                Preserve @code{@ref{$TEST}} until the end of the current line.
 2100: * TROLLBACK::                           Roll back all pending transactions.
 2101: * TSTART::                              Introduce a new transaction processing level.
 2102: * USE::                                 Set the currently-active input/output device.
 2103: * VIEW::                                Modify FreeM internal parameters.
 2104: * WRITE::                               Write output to current input/output device.
 2105: * XECUTE::                              Interpret string as M code.
 2106: * ZASSERT::                             Raise error when a conditional expression evaluates @emph{false}.
 2107: * ZBREAK::                              Enable/disable ZBREAK mode.
 2108: * ZCONST::                              Define a constant that cannot be altered after initial definition.
 2109: * ZEDIT::                               Edit a routine using an external editor.
 2110: * ZGOTO::                               @code{GOTO} with @code{BREAK} control.
 2111: * ZHALT::                               Exit FreeM job with return value.
 2112: * ZINSERT::                             Insert code into routine buffer.
 2113: * ZJOB::                                Invoke job, ignoring any timeouts.
 2114: * ZLOAD::                               Load routine into routine buffer.
 2115: * ZMAP::                                Map a global name to a non-default namespace.
 2116: * ZNEW::                                Unknown.
 2117: * ZPRINT::                              Print contents of routine buffer.
 2118: * ZQUIT::                               Quit multiple stack levels at once.
 2119: * ZREMOVE::                             Remove code from routine buffer.
 2120: * ZSAVE::                               Save routine buffer to disk.
 2121: * ZTHROW::                              Programmatically raise an error condition.
 2122: * ZTRAP::                               Raise a FreeM error.
 2123: * ZUNMAP::                              Remove a mapping of a global to a non-default namespace.
 2124: * ZWATCH::                              Enable or disable watchpoints, or set or clear watchpoints on specified globals, locals, or structured system variables.
 2125: * ZWITH::                               Set prefix for future variable references.
 2126: * ZWRITE::                              Write local variable, global, or structured system variable to @code{@ref{$IO}}.
 2127: @end menu
 2128: 
 2129: @node @@
 2130: @section @@
 2131: @cindex @@
 2132: @cindex commands, @@
 2133: @cindex commands, implementation-specific
 2134: @cindex commands, non-standard
 2135: 
 2136: Executes FreeM code @emph{expr V mcode}.
 2137: 
 2138: @emph{Syntax}
 2139: 
 2140: @example
 2141: @@@emph{expr V mcode}
 2142: @end example
 2143: 
 2144: @emph{Example (Using Variable)}
 2145: 
 2146: @example
 2147: DEFAULT.USER> SET FOO="WRITE ""HELLO WORLD"",!"
 2148: DEFAULT.USER> @@FOO
 2149: 
 2150: HELLO WORLD
 2151: 
 2152: DEFAULT.USER>
 2153: @end example
 2154: 
 2155: @emph{Example (Using String Literal)}
 2156: 
 2157: @example
 2158: DEFAULT.USER> @@"WRITE ""HELLO WORLD"",!"
 2159: 
 2160: HELLO WORLD
 2161: 
 2162: DEFAULT.USER>
 2163: @end example
 2164: 
 2165: @emph{Example (Using Indirection)}
 2166: 
 2167: @example
 2168: DEFAULT.USER> SET FOO="BAR"
 2169: 
 2170: DEFAULT.USER> SET BAR="WRITE ""HELLO WORLD"",!"
 2171: 
 2172: DEFAULT.USER> @@@@FOO
 2173: 
 2174: HELLO WORLD
 2175: 
 2176: DEFAULT.USER>
 2177: @end example
 2178: 
 2179: 
 2180: @node !
 2181: @section !
 2182: @cindex !
 2183: @cindex commands, !
 2184: @cindex commands, external
 2185: @cindex commands, non-standard
 2186: @emph{FreeM Extension}
 2187: 
 2188: Invokes a shell to run @emph{<external-command>} from within FreeM. This temporarily disables @command{SIGALRM} handling in FreeM, which may interrupt the use of event-driven M programming commands including @command{ESTART} and @command{ESTOP}.
 2189: 
 2190: If the @command{<} character is supplied immediately preceding @emph{<external-command>}, FreeM will append the contents of M local variable @code{%} to @emph{<external-command>} as standard input.
 2191: 
 2192: If the @command{>} character is supplied immediately preceding @emph{<external-command>}, FreeM will take the standard output stream of @emph{<external-command>} and store it in M local variable @code{%}.
 2193: 
 2194: @code{%} contains the number of lines in the input or output. @code{%(1)..%(@emph{n})} contains the data for lines 1-@emph{n}.
 2195: 
 2196: @node !!
 2197: @section !!
 2198: @cindex !!
 2199: @cindex commands, !!
 2200: @cindex commands, external
 2201: @cindex commands, non-standard
 2202: @emph{FreeM Extension}
 2203: 
 2204: Launches a subshell within the FreeM direct mode, allowing the user to run operating system commands.
 2205: 
 2206: @example
 2207: DEFAULT.USER> !!
 2208: 
 2209: Type Ctrl-D to exit from the shell
 2210: $ uname -a
 2211: Linux hesperos 4.19.0-17-amd64 #1 SMP Debian 4.19.194-3 (2021-07-18) x86_64 GNU/Linux
 2212: $ exit
 2213: 
 2214: DEFAULT.USER> 
 2215: @end example
 2216: 
 2217: 
 2218: @node ABLOCK
 2219: @section ABLOCK
 2220: @cindex ABLOCK
 2221: @cindex commands, ABLOCK
 2222: 
 2223: Increments the event block counter for one or more event classes. While the block counter for an event class is greater than zero, registered event handlers for that event class will not execute, and will instead be queued for later execution once the block counter reaches zero (all blocks removed).
 2224: 
 2225: An implicit @code{ABLOCK} on all event classes occurs when an event handler subroutine is executing. As soon as a @code{QUIT} is reached within an event handler, an implicit @code{ABLOCK} will occur.
 2226: 
 2227: @emph{Syntax}
 2228: 
 2229: @example
 2230:   ABLOCK@emph{:postcondition}
 2231: @end example
 2232: 
 2233: In its argumentless form, @code{ABLOCK} increments the block counter for @emph{all} event classes, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2234: 
 2235: @example
 2236:   ABLOCK@emph{:postcondition} @emph{evclass1}...,@emph{evclassN}
 2237: @end example
 2238: 
 2239: In its inclusive form, @code{ABLOCK} increments the block counters for all event classes named in the list, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2240: 
 2241: @example
 2242:   ABLOCK@emph{:postcondition} (@emph{evclass1}...,@emph{evclassN}
 2243: @end example
 2244: 
 2245: In its exclusive form, @code{ABLOCK} increments the block counters for all event classes @emph{except for} those named in the list, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2246: 
 2247: 
 2248: @node ASTART
 2249: @section ASTART
 2250: @cindex ASTART
 2251: @cindex commands, ASTART
 2252: 
 2253: Enables asynchronous event handling for one or more event classes.
 2254: 
 2255: @emph{Syntax}
 2256: 
 2257: @example
 2258:   ASTART@emph{:postcondition}
 2259: @end example
 2260: 
 2261: In its argumentless form, @code{ASTART} enables asynchronous event handling for all event classes, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2262: 
 2263: @example
 2264:   ASTART@emph{:postcondition} @emph{evclass1}...,@emph{evclassN}
 2265: @end example
 2266: 
 2267: In its inclusive form, @code{ASTART} enables asynchronous event handling for all event classes named in the list, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2268: 
 2269: @example
 2270:   ASTART@emph{:postcondition} (@emph{evclass1}...,@emph{evclassN})
 2271: @end example
 2272: 
 2273: In its exclusive form, @code{ASTART} enables asynchronous event handling for all event classes @emph{except for} those named in the list, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2274: 
 2275: @node ASTOP
 2276: @section ASTOP
 2277: @cindex ASTOP
 2278: @cindex commands, ASTOP
 2279: 
 2280: Disables asynchronous event handling for one or more event classes.
 2281: 
 2282: @emph{Syntax}
 2283: 
 2284: @example
 2285:   ASTOP@emph{:postcondition}
 2286: @end example
 2287: 
 2288: In its argumentless form, @code{ASTOP} disables asynchronous event handling for all event classes, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2289: 
 2290: @example
 2291:   ASTOP@emph{:postcondition} @emph{evclass1}...,@emph{evclassN}
 2292: @end example
 2293: 
 2294: In its inclusive form, @code{ASTOP} disables asynchronous event handling for all event classes named in the list, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2295: 
 2296: @example
 2297:   ASTOP@emph{:postcondition} (@emph{evclass1}...,@emph{evclassN})
 2298: @end example
 2299: 
 2300: In its exclusive form, @code{ASTOP} disables asynchronous event handling for all event classes @emph{except for} those named in the list, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2301: 
 2302: @node AUNBLOCK
 2303: @section AUNBLOCK
 2304: @cindex AUNBLOCK
 2305: @cindex commands, AUNBLOCK
 2306: 
 2307: Decrements the event block counter for one or more event classes.
 2308: 
 2309: @emph{Syntax}
 2310: 
 2311: @example
 2312:   AUNBLOCK@emph{:postcondition}
 2313: @end example
 2314: 
 2315: In its argumentless form, @code{AUNBLOCK} decrements the block counter for @emph{all} event classes, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2316: 
 2317: @example
 2318:   AUNBLOCK@emph{:postcondition} @emph{evclass1}...,@emph{evclassN}
 2319: @end example
 2320: 
 2321: In its inclusive form, @code{AUNBLOCK} decrements the block counters for all event classes named in the list, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2322: 
 2323: @example
 2324:   AUNBLOCK@emph{:postcondition} (@emph{evclass1}...,@emph{evclassN}
 2325: @end example
 2326: 
 2327: In its exclusive form, @code{AUNBLOCK} decrements the block counters for all event classes @emph{except for} those named in the list, provided the optional @emph{postcondition} is either @emph{true} or omitted.
 2328: 
 2329: 
 2330: @node BREAK
 2331: @section BREAK
 2332: @cindex BREAK
 2333: @cindex commands, BREAK
 2334: 
 2335: Interrupts running routine to allow interactive debugging.
 2336: 
 2337: @emph{Syntax}
 2338: 
 2339: @example
 2340: @code{BREAK@emph{:postcondition}}
 2341: @end example
 2342: 
 2343: In its argumentless form, @code{BREAK} suspends execution of running code, provided the optional @emph{postcondition} is @emph{true} or omitted.
 2344: 
 2345: @example
 2346: @code{BREAK@emph{:postcondition} @emph{breakflag}}
 2347: @end example
 2348: 
 2349: @emph{FreeM Extension}
 2350: 
 2351: In its single-argument form, @code{BREAK} enters the interactive debugger or sets @emph{Ctrl-C} handling and error handling characteristics, provided the optional @emph{postcondition} is @emph{true} or omitted.
 2352: The following table enumerates the possible values of @emph{breakflag}
 2353: 
 2354: @table @code
 2355: @item "DEBUG"
 2356: Enters the interactive debugger
 2357: @item 0
 2358: Disables @emph{Ctrl-C} handling
 2359: @item -2
 2360: Enables normal FreeM error handling
 2361: @item 2
 2362: Enables @emph{Digital Standard MUMPS} v2 error handling
 2363: @item @emph{any integer value other than 0, 2, or -2}
 2364: Enables @emph{Ctrl-C} handling
 2365: @end table
 2366: 
 2367: @node CLOSE
 2368: @section CLOSE
 2369: @cindex CLOSE
 2370: @cindex commands, CLOSE
 2371: 
 2372: Closes an input/output device.
 2373: 
 2374: @emph{Syntax}
 2375: 
 2376: @example
 2377: @code{CLOSE@emph{:postcondition}}
 2378: @end example
 2379: 
 2380: In its argumentless form, @code{CLOSE} closes all I/O devices except for device 0 (the @code{HOME} device), provided the optional @emph{postcondition} is @emph{true} or omitted.
 2381: 
 2382: @example
 2383: @code{CLOSE@emph{:postcondition} @emph{channel}}
 2384: @end example
 2385: 
 2386: In its single-argument form, @code{CLOSE} closes the I/O device associated with channel @emph{channel}, provided that @emph{channel} represents a currently-open device, and the optional @emph{postcondition} is @emph{true} or omitted.
 2387: 
 2388: @node DO
 2389: @section DO
 2390: @cindex DO
 2391: @cindex commands, DO
 2392: 
 2393: In its inclusive form, transfers program control to one or more specified subroutines, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. Line levels of entryrefs specified in the argument list must be one, or error @code{M14} is raised.
 2394: 
 2395: @emph{Syntax}
 2396: 
 2397: @example
 2398: DO[@emph{:postcondition}] @emph{entryref}[@emph{:postcondition}[,...]]
 2399: @end example
 2400: 
 2401: @cartouche
 2402: @quotation
 2403: @emph{Non-Standard Behavior}
 2404: 
 2405: FreeM allows @code{DO} @emph{entryref}s to follow the format of @code{+@emph{intexpr}}. In this case, the value of @emph{intexpr} will be interpreted as an offset from the first line of the current routine.
 2406: @end quotation
 2407: @end cartouche
 2408: 
 2409: In its argumentless form, transfers control to the following block of code where the line level is one greater than the level at which @code{DO} was encountered, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2410: 
 2411: @emph{Syntax}
 2412: 
 2413: @example
 2414: DO[@emph{:postcondition}]
 2415: @end example
 2416: 
 2417: @node ELSE
 2418: @section ELSE
 2419: @cindex ELSE
 2420: @cindex commands, ELSE
 2421: 
 2422: Executes the remainder of the line of code on which @code{ELSE} is encountered only if @code{$TEST} evaluates to @emph{false}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2423: 
 2424: @emph{Syntax}
 2425: 
 2426: @example
 2427: ELSE[@emph{:postcondition}]
 2428: @end example
 2429: 
 2430: @cartouche
 2431: @quotation
 2432: @emph{Non-Standard Behavior}
 2433: 
 2434: FreeM allows a @emph{postcondition} on @code{ELSE}. While explicitly forbidden in the @emph{Standard}, it was decided that FreeM should allow postconditions everywhere, both for the sake of foolish consistency (the likes of which Emerson warned against), and for the benefit of entrants to a hypothetical future obfuscated M contest, and those with a Machiavellian predisposition to wicked perversions and undue cleverness.
 2435: 
 2436: Using postconditions on @code{ELSE} should be strictly avoided in production code, as they have no practical use, and may contribute to technical debt, hardening of the arteries, hobgoblins, a small mind, a surfeit of logic, climate change, @emph{Daily WTF} rants, or the meltdown of global financial markets.
 2437: @end quotation
 2438: @end cartouche
 2439: 
 2440: @node FOR
 2441: @section FOR
 2442: @cindex FOR
 2443: @cindex commands, FOR
 2444: 
 2445: In its argumentless form, repeatedly executes the remainder of the line on which @code{FOR} was encountered until a @code{QUIT}, @code{GOTO}, or end-of-line is encountered, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2446: 
 2447: @emph{Syntax}
 2448: 
 2449: @example
 2450: FOR[@emph{:postcondition}]
 2451: @end example
 2452: 
 2453: @cartouche
 2454: @quotation
 2455: @emph{Non-Standard Behavior}
 2456: 
 2457: When @code{$DIALECT} is set to @code{FREEM}, FreeM allows a @emph{postcondition} on @code{FOR}. Much like postconditions on @code{ELSE} and @code{IF}, this is explicitly forbidden in the @emph{standard}. The expression contained in the @emph{postcondition} is evaluated on each iteration of the @code{FOR} loop, and if it does not evaluate @emph{true}, the loop will be immediately exited. The effect is roughly similar to @code{WHILE} constructs present in other languages, but absent from standard M.
 2458: 
 2459: As with all non-standard features of FreeM, please exercise caution when using this feature, especially in code that is expected to run in other, less preternaturally-inclined M implementations.
 2460: @end quotation
 2461: @end cartouche
 2462: 
 2463: In its sentinel form, repeatedly executes the remainder of the line and sets a sentinel variable on each iteration, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2464: 
 2465: On the first iteration of the loop, @emph{glvn} will be set to @emph{initalizer-expression}. On each subsequent iteration, @emph{glvn} will be incremented by @emph{increment-expression}, and the loop will terminate when @emph{glvn} meets or exceeds the value of @emph{max-expression}.
 2466: 
 2467: @emph{Syntax}
 2468: 
 2469: @example
 2470: FOR[@emph{:postcondition}] @emph{glvn}=@emph{initializer-expression}:@emph{increment-expression}:@emph{max-expression}
 2471: @end example
 2472: 
 2473: @emph{Example}
 2474: 
 2475: @example
 2476: DEFAULT.USER> FOR I=1:1:10 WRITE I,!
 2477: 
 2478: 1
 2479: 2
 2480: 3
 2481: 4
 2482: 5
 2483: 6
 2484: 7
 2485: 8
 2486: 9
 2487: 10
 2488: 
 2489: DEFAULT.USER> FOR I=2:2:10 WRITE I,!
 2490: 
 2491: 2
 2492: 4
 2493: 6
 2494: 8
 2495: 10
 2496: @end example
 2497: 
 2498: In its explicit parameter form, a variable is set to each of a series of explicit values, once per iteration, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. The loop terminates when no more values are available.
 2499: 
 2500: @emph{Syntax}
 2501: 
 2502: @example
 2503: FOR[@emph{:postcondition}] @emph{glvn}=@emph{expr1}[,..@emph{exprN}]
 2504: @end example
 2505: 
 2506: @emph{Example}
 2507: 
 2508: @example
 2509: DEFAULT.USER> FOR I=60,"FOO",-3,"George",1450,$HOROLOG WRITE I,!
 2510: 
 2511: 60
 2512: FOO
 2513: -3
 2514: George
 2515: 1450
 2516: 66106,52388
 2517: @end example
 2518: 
 2519: @node GOTO
 2520: @section GOTO
 2521: @cindex GOTO
 2522: @cindex commands, GOTO
 2523: 
 2524: Transfers program execution to another line of code, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. Attempting to @code{GOTO} a different line level or a different block when the line level of @code{GOTO} is greater than one will raise error @code{M45}.
 2525: 
 2526: @emph{Syntax}
 2527: 
 2528: @example
 2529: GOTO[@emph{:postcondition}] @emph{entryref}
 2530: @end example
 2531: 
 2532: @cartouche
 2533: @quotation
 2534: @emph{Non-Standard Behavior}
 2535: 
 2536: FreeM allows @code{GOTO} @emph{entryref}s to follow the format of @code{+@emph{intexpr}}. In this case, the value of @emph{intexpr} will be interpreted as an offset from the first line of the current routine.
 2537: @end quotation
 2538: @end cartouche
 2539: 
 2540: 
 2541: @node HALT
 2542: @section HALT
 2543: @cindex HALT
 2544: @cindex commands, HALT
 2545: 
 2546: Halts program execution and frees resources allocated during execution, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2547: 
 2548: @emph{Syntax}
 2549: 
 2550: @example
 2551: HALT[@emph{:postcondition}]
 2552: @end example
 2553: 
 2554: @node HANG
 2555: @section HANG
 2556: @cindex HANG
 2557: @cindex commands, HANG
 2558: 
 2559: Temporarily suspends the program for @emph{expr} seconds, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. Values of @emph{expr} that are zero or less than zero are ignored.
 2560: 
 2561: @emph{Syntax}
 2562: 
 2563: @example
 2564: HANG[@emph{:postcondition}] @emph{expr}
 2565: @end example
 2566: 
 2567: @cartouche
 2568: @quotation
 2569: @emph{Non-Standard Behavior}
 2570: 
 2571: FreeM supports sub-second values for @emph{expr}.
 2572: @end quotation
 2573: @end cartouche
 2574: 
 2575: @node IF
 2576: @section IF
 2577: @cindex IF
 2578: @cindex commands, IF
 2579: 
 2580: In its argumented form, allows the remainder of the line of code following @code{IF} to execute only if all @emph{tvexpr}s evaluate to @emph{true}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2581: 
 2582: @emph{Syntax}
 2583: @example
 2584: IF[@emph{:postcondition}] @emph{tvexpr}[,...@emph{tvexpr}]
 2585: @end example
 2586: 
 2587: In its argumentless form, allows the remainder of the line of code following @code{IF} to execute only if @code{$TEST} evaluates to @emph{1}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2588: 
 2589: 
 2590: @emph{Syntax}
 2591: @example
 2592: IF[@emph{:postcondition}]  @emph{command...}
 2593: @end example
 2594: 
 2595: @cartouche
 2596: @quotation
 2597: @emph{Style Recommendation}
 2598: 
 2599: In the interest of readability and maintainability, we recommend avoiding the argumentless form of @code{IF} in new code. It is an obsolete relic of an era when routine sizes were severely limited, and can be difficult to spot, as the use of whitespace (@code{IF  @emph{command}}) makes the intent of its use non-obvious at a glance. It is also far too easy to inadvertently delete the extra space, leading to program errors easily avoided otherwise.
 2600: 
 2601: We recommend explicitly checking the value of @code{$TEST} instead, as in @code{IF $TEST @emph{command}} or @code{@emph{command}:$TEST ...}, as this makes the intent immediately clear both to M newcomers and seasoned experts, and sacrifices nothing of value, even on the oldest computer systems where FreeM can be used today.
 2602: @end quotation
 2603: @end cartouche
 2604: 
 2605: @node JOB
 2606: @section JOB
 2607: @cindex JOB
 2608: @cindex commands, JOB
 2609: 
 2610: Executes @emph{entryref} in a separate process, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2611: 
 2612: @emph{Syntax}
 2613: @example
 2614: JOB[@emph{:postcondition}] @emph{entryref}[:@emph{job-parameters}[:@emph{timeout}]]
 2615: @end example
 2616: 
 2617: If @emph{timeout} is supplied, FreeM will set @code{$TEST} to @emph{1} if the child process completes within @emph{timeout} seconds.
 2618: 
 2619: @node KILL
 2620: @section KILL
 2621: @cindex KILL
 2622: @cindex commands, KILL
 2623: 
 2624: In its inclusive form, @code{KILL} deletes the specified @emph{glvn}s and their descendant subscripts, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2625: 
 2626: @emph{Syntax}
 2627: @example
 2628: KILL[@emph{:postcondition}] @emph{glvn}[,...@emph{glvn}]
 2629: @end example
 2630: 
 2631: In its exclusive form, @code{KILL} deletes all local variables @emph{except} for those specified by @emph{lvn}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2632: 
 2633: @emph{Syntax}
 2634: @example
 2635: KILL[@emph{:postcondition}] (@emph{lvn}[,...@emph{lvn}])
 2636: @end example
 2637: 
 2638: In its argumentless form, @code{KILL} deletes all local variables, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2639: 
 2640: @emph{Syntax}
 2641: @example
 2642: KILL[@emph{:postcondition}]
 2643: @end example
 2644: 
 2645: @node KSUBSCRIPTS
 2646: @section KSUBSCRIPTS
 2647: @cindex KSUBSCRIPTS
 2648: @cindex commands, KSUBSCRIPTS
 2649: 
 2650: Kills only the descendant subscripts (but not the data value) of a referenced global, local, or SSVN (where allowed).
 2651: 
 2652: @emph{Syntax}
 2653: 
 2654: @example
 2655: KSUBSCRIPTS@emph{:postcondition} @emph{var1},...
 2656: @end example
 2657: 
 2658: In the above @emph{inclusive} form, @code{KVALUE} will kill the descendant subscripts at each local, global, or SSVN node specified in the list (provided that the optional @emph{postcondition} is @emph{true} or omitted), but will leave the data value intact.
 2659: 
 2660: @cartouche
 2661: @quotation
 2662: @emph{Note}
 2663: The below @emph{argumentless} and @emph{exclusive} forms of @code{KSUBSCRIPTS} are not implemented in FreeM, as of version 0.65.1-rc1, but are planned for a future release.
 2664: @end quotation
 2665: @end cartouche
 2666: 
 2667: @example
 2668: KSUBSCRIPTS@emph{:postcondition}
 2669: @end example
 2670: 
 2671: In the above @emph{argumentless} form, @code{KSUBSCRIPTS} will kill the descendant subscripts at the root of each local variable (provided that the optional @emph{postcondition} is @emph{true} or omitted), but will leave data values intact.
 2672: 
 2673: @example
 2674: KSUBSCRIPTS@emph{:postcondition} (@emph{var1},...)
 2675: @end example
 2676: 
 2677: In the above @emph{exclusive} form, @code{KSUBSCRIPTS} will kill the descendant subscripts of all local variables, @emph{with the exception of} those named in the list, provided that the optional @emph{postcondition} is @emph{true} or omitted, while leaving their data values intact.
 2678: 
 2679: 
 2680: @node KVALUE
 2681: @section KVALUE
 2682: @cindex KVALUE
 2683: @cindex commands, KVALUE
 2684: 
 2685: Kills only the data value (but not descendant subscripts) of a referenced global, local, or SSVN (where allowed).
 2686: 
 2687: @emph{Syntax}
 2688: 
 2689: @example
 2690: KVALUE@emph{:postcondition} @emph{var1},...
 2691: @end example
 2692: 
 2693: In the above @emph{inclusive} form, @code{KVALUE} will kill the data values at each local, global, or SSVN node specified in the list (provided that the optional @emph{postcondition} is @emph{true} or omitted), but will leave descendant subscripts intact.
 2694: 
 2695: @cartouche
 2696: @quotation
 2697: @emph{Note}
 2698: The below @emph{argumentless} and @emph{exclusive} forms of @code{KVALUE} are not implemented in FreeM, as of version 0.65.1-rc1, but are planned for a future release.
 2699: @end quotation
 2700: @end cartouche
 2701: 
 2702: @example
 2703: KVALUE@emph{:postcondition}
 2704: @end example
 2705: 
 2706: In the above @emph{argumentless} form, @code{KVALUE} will kill the data values at the root of each local variable (provided that the optional @emph{postcondition} is @emph{true} or omitted), but will leave descendant subscripts intact.
 2707: 
 2708: @example
 2709: KVALUE@emph{:postcondition} (@emph{var1},...)
 2710: @end example
 2711: 
 2712: In the above @emph{exclusive} form, @code{KVALUE} will kill the data values of all local variables, @emph{with the exception of} those named in the list, provided that the optional @emph{postcondition} is @emph{true} or omitted, while leaving their descendant subscripts intact.
 2713: 
 2714: @node LOCK
 2715: @section LOCK
 2716: @cindex LOCK
 2717: @cindex commands, LOCK
 2718: 
 2719: Acquires or releases ownership of names.
 2720: 
 2721: In its argumentless form, @code{LOCK} releases ownership of all names previously locked by the current process, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2722: 
 2723: @emph{Syntax}
 2724: @example
 2725: LOCK[@emph{:postcondition}]
 2726: @end example
 2727: 
 2728: In its incremental form, increments or decrements the lock counter for each specified @emph{name}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. Ownership of each @emph{name} is considered to be the current process as long as the lock counter for @emph{name} is greater than zero. If @emph{timeout} is specified, FreeM will wait no more than @emph{timeout} seconds in attempting to acquire ownership of @emph{name}.
 2729: 
 2730: If @code{LOCK} succeeds within @emph{timeout}, @code{$TEST} is set to @emph{1}. Otherwise, @code{$TEST} is set to @emph{0}.
 2731: 
 2732: @emph{Syntax}
 2733: @example
 2734: LOCK[@emph{:postcondition}] [+|-]@emph{name}[:@emph{timeout}][,...[+|-]@emph{name}[:@emph{timeout}]]
 2735: @end example
 2736: 
 2737: @emph{Example}
 2738: 
 2739: This example will increment the lock counter for @code{^SNW} and decrement the lock counter for @code{^MJR}.
 2740: 
 2741: @example
 2742: LOCK +^SNW,-^MJR
 2743: @end example
 2744: 
 2745: In its non-incremental form, @code{LOCK} releases all @code{LOCK}s held by the current process, and then attempts to acquire a lock on each @emph{name}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. If @emph{timeout} is supplied, FreeM will attempt to lock @emph{name} for no more than @emph{timeout} seconds.
 2746: 
 2747: If @code{LOCK} succeeds within @emph{timeout}, @code{$TEST} is set to @emph{1}. Otherwise, @code{$TEST} is set to @emph{0}.
 2748: 
 2749: @emph{Syntax}
 2750: @example
 2751: LOCK[@emph{:postcondition}] @emph{name}[:@emph{timeout}][,...@emph{name}[:@emph{timeout}]]
 2752: @end example
 2753: 
 2754: @node MERGE
 2755: @section MERGE
 2756: @cindex MERGE
 2757: @cindex commands, MERGE
 2758: 
 2759: Merges the contents of one global, local, or SSVN subtree to another global, local, or SSVN.
 2760: 
 2761: @emph{Syntax}
 2762: 
 2763: @example
 2764: @code{MERGE A=^$JOB}
 2765: @end example
 2766: 
 2767: The above example will merge the @code{^$JOB} SSVN into the @code{A} local. Note that the FreeM implementation of @code{MERGE} does not yet support multiple merge arguments. Returns error @code{M19} if either the source or the target variable are descendants of each other.
 2768: 
 2769: @node NEW
 2770: @section NEW
 2771: @cindex NEW
 2772: @cindex commands, NEW
 2773: 
 2774: In all forms of @code{NEW}, @emph{name} must be a local variable name or @code{NEW}-able structured or intrinsic system variable.
 2775: 
 2776: In its inclusive form, @code{NEW} saves each specified @emph{name} on the process stack and removes it, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.  When the current stack frame is exited, the previous values are restored.
 2777: 
 2778: @emph{Syntax}
 2779: 
 2780: @example
 2781: NEW[@emph{:postcondition}] @emph{name}[,...@emph{name}]
 2782: @end example
 2783: 
 2784: In its exclusive form, @code{NEW} saves all local variables @emph{except} those named (each @emph{name}) and removes them, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. When the current stack frame is exited, the previous values are restored.
 2785: 
 2786: @emph{Syntax}
 2787: @example
 2788: NEW[@emph{:postcondition}] (@emph{name}[,...@emph{name}])
 2789: @end example
 2790: 
 2791: In its argumentless form, @code{NEW} saves all local variables and removes them, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. When the current stack frame is exited, the previous values are restored.
 2792: 
 2793: @emph{Syntax}
 2794: @example
 2795: NEW@emph{:postcondition} @emph{name}=@emph{expr}
 2796: @end example
 2797: 
 2798: In its initializing form, @code{NEW} stacks variable @emph{name} and sets its value to @emph{expr}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. When the current stack frame is exited, the previous value is restored.
 2799: 
 2800: @emph{Syntax}
 2801: @example
 2802: NEW@emph{:postcondition} @emph{name}=$%@emph{^CLASS}(@emph{initializer-list})
 2803: @end example
 2804: 
 2805: In its object-oriented form, @code{NEW} creates an instance of class @emph{^CLASS} in local variable @emph{name} and calls the constructor of @emph{^CLASS}, passing @emph{initializer-list} as its argument(s).
 2806: 
 2807: @node OPEN
 2808: @section OPEN
 2809: @cindex OPEN
 2810: @cindex commands, OPEN
 2811: 
 2812: Opens sequential or socket I/O devices and files and associates them with a numeric FreeM input/output channel.
 2813: 
 2814: @emph{Syntax (Sequential Files)}
 2815: 
 2816: @example
 2817: @code{OPEN@emph{:postcondition} @emph{channel}:"@emph{filename}/@emph{access-mode}"}
 2818: @end example
 2819: 
 2820: Opens @emph{filename} for reading and/or writing, and associates the file with FreeM I/O channel @emph{channel}, provided that the optional @emph{postcondition} is @emph{true} or omitted.
 2821: The below table lists the valid options for @emph{access-mode}:
 2822: 
 2823: @table @code
 2824: @item r
 2825: Read-only access
 2826: @item w
 2827: Create a new file for write access
 2828: @item a
 2829: Write access; append to existing file
 2830: @item r+
 2831: Read/write access
 2832: @end table
 2833: 
 2834: @cartouche
 2835: @quotation
 2836: @emph{I/O Path}
 2837: 
 2838: You cannot specify a fully-qualified filesystem path in the FreeM @code{OPEN} command. By default, FreeM will assume that @emph{filename} exists in the directory indicated in @code{^$JOB($JOB,"CWD")}. If you wish to
 2839: access files in other directories, you must first set the @emph{I/O Path} in @code{^$JOB($JOB,"IOPATH")}.
 2840: 
 2841: The following example will set the I/O path to @code{/etc}:
 2842: 
 2843: @example
 2844: @code{SET ^$JOB($JOB,"IOPATH")="/etc"}
 2845: @end example
 2846: 
 2847: @end quotation
 2848: @end cartouche
 2849: 
 2850: If @emph{channel} was already @code{OPEN}ed in the current process, calling @code{OPEN} on the same channel again implicitly closes the file or device currently associated with @emph{channel}.
 2851: 
 2852: @emph{Syntax (Network Sockets)}
 2853: 
 2854: Network sockets use a dedicated range of FreeM I/O channels ranging from 100-255. @code{OPEN}ing a socket I/O channel does @emph{not} implicitly connect the socket. Connecting the socket to the specified remote host is accomplished by the @code{/CONNECT} control mnemonic supplied to the @code{USE} command.
 2855: 
 2856: @example
 2857:   OPEN@emph{:postcondition} @emph{socket-channel}:"@emph{hostname-or-address}:@emph{port}:@emph{address-family}:@emph{connection-type}"
 2858: @end example
 2859: 
 2860: @emph{Socket Parameters}
 2861: 
 2862: @table @emph
 2863: 
 2864: @item socket-channel
 2865: The socket I/O channel to use. This must be in the range of 100-255.
 2866: 
 2867: @item hostname-or-address
 2868: The hostname or IP address to connect to. If a hostname is supplied, @code{OPEN} will implictly do a name lookup, the mechanism of which is typically determined by the configuration of @code{/etc/nsswitch.conf} on most UNIX and UNIX-like platforms.
 2869: 
 2870: @item port
 2871: The TCP or UDP port to which the socket will connect on the remote host.
 2872: 
 2873: @item address-family
 2874: The address family to use. Either @emph{IPV4} or @emph{IPV6}.
 2875: 
 2876: @item connection-type
 2877: Which connection type to use. Either @emph{TCP} or @emph{UDP}.
 2878: 
 2879: @end table
 2880: 
 2881: If you do not specify the address family and connection type, they will default to @emph{IPV4} and @emph{TCP}, respectively.
 2882: 
 2883: @node QUIT
 2884: @section QUIT
 2885: @cindex QUIT
 2886: @cindex commands, QUIT
 2887: 
 2888: @code{QUIT} will end execution of the current process level, optionally returning @emph{expr}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2889: 
 2890: @code{QUIT} with @emph{expr} when an argument is not expected will raise error @code{M16}; @code{QUIT} without @emph{expr} when an argument is expected will raise error @code{M17}.
 2891: 
 2892: Argumentless @code{QUIT} may also be used to exit a @code{FOR} loop occurring on the same line.
 2893: 
 2894: @emph{Syntax}
 2895: @example
 2896: QUIT[@emph{:postcondition}] [@emph{expr}]
 2897: @end example
 2898: 
 2899: @node READ
 2900: @section READ
 2901: @cindex READ
 2902: @cindex commands, READ
 2903: 
 2904: The @code{READ} command takes input from I/O channel @code{$IO} and stores it into specified variables, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2905: 
 2906: @emph{Syntax}
 2907: @example
 2908: READ[@emph{:postcondition}] @emph{read-argument}[,...@emph{read-argument}]
 2909: @end example
 2910: 
 2911: Each @emph{read-argument} may be one of the following:
 2912: 
 2913: @table @asis
 2914: 
 2915: @item String Literal
 2916: String literal @emph{read-argument}s will be output to @code{$IO} unmodified.
 2917: 
 2918: @item Format Specifier
 2919: One or more of the following:
 2920: 
 2921: @table @asis
 2922: @item @code{!} (newline)
 2923: Advances the cursor down by one line and returns it to the first column.
 2924: 
 2925: @item @code{#} (form-feed)
 2926: Advances the screen down by @code{$ZROWS} and moves the cursor to the upper-left corner of the screen.
 2927: 
 2928: @item @code{?@emph{n}} (position)
 2929: Advances the cursor and @code{$X} forward to position @emph{n}.
 2930: 
 2931: @end table
 2932: 
 2933: @item Single-Character Read (@code{*@emph{variable-name}[@emph{:timeout}]})
 2934: Reads one character into variable @emph{variable-name}. If the optional @emph{timeout} is specified, will wait @emph{timeout} seconds to retrieve one character. If a character is read within @emph{timeout} seconds, @code{$TEST} will be set to @emph{1}. If no character is read within @emph{timeout} seconds, @code{$TEST} will be set to @emph{0}.
 2935: 
 2936: @item Variable-Length Character Read (@code{@emph{variable-name}[@emph{:timeout}]})
 2937: Reads characters into @emph{variable-name} until the character or character pair in @code{^$DEVICE(@emph{io-channel},"OPTIONS","TERMINATOR")} is encountered. If the optional @emph{timeout} is specified, will wait @emph{timeout} seconds to retrieve characters. If characters are read within @emph{timeout} seconds, @code{$TEST} will be set to @emph{1}. If no character is read within @emph{timeout} seconds, @code{$TEST} will be set to @emph{0}.
 2938: 
 2939: @item Fixed-Length Character Read (@code{@emph{variable-name}#@emph{count}[@emph{:timeout}]})
 2940: Reads @emph{count} characters into @emph{variable-name}. If the optional @emph{timeout} is specified, will wait @emph{timeout} seconds to retrieve characters. If characters are read within @emph{timeout} seconds, @code{$TEST} will be set to @emph{1}. If no character is read within @emph{timeout} seconds, @code{$TEST} will be set to @emph{0}.
 2941: 
 2942: @item Control Mnemonic (@code{/@emph{control-mnemonic}[@emph{(arg1[,...argN])}]})
 2943: Outputs X3.64 control mnemonic @emph{control-mnemonic} to @code{$IO}. Please see the appendix on X3.64 Control Mnemonics for more information.
 2944: 
 2945: @end table
 2946: 
 2947: @node SET
 2948: @section SET
 2949: @cindex SET
 2950: @cindex commands, SET
 2951: 
 2952: The @code{SET} command places values into one or more variables, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2953: 
 2954: @emph{Syntax}
 2955: @example
 2956: SET[@emph{:postcondition}] @emph{set-argument}[=@emph{expression} | @emph{postfix-operator}][@emph{,...set-argument}[=@emph{expression} | @emph{postfix-operator}]]
 2957: @end example
 2958: 
 2959: Each @emph{set-argument} can be:
 2960: 
 2961: @table @asis
 2962: @item @emph{variable-name}
 2963: A local variable, global variable, writable intrinsic special variable, or writable structured system variable.
 2964: 
 2965: @item @emph{lhs-function}
 2966: @code{$EXTRACT} or @code{$PIECE}.
 2967: @end table
 2968: 
 2969: If any grouping of @emph{set-argument}s is surrounded by parentheses, all @emph{set-argument}s in the parenthesized group will be set to the result of @emph{expression}.
 2970: 
 2971: If @emph{postfix-operator} is used instead of @code{=@emph{expression}}, the results of applying @emph{postfix-operator} to the @emph{set-argument} will be stored in @emph{set-argument}. @emph{postfix-operator} may not be used following a parenthesized group of @emph{set-argument}s.
 2972: 
 2973: @emph{Example (postfix-operator)}
 2974: 
 2975: @example
 2976: SET A++,B-- ; increments A, decrements B
 2977: @end example
 2978: 
 2979: @node TCOMMIT
 2980: @section TCOMMIT
 2981: @cindex TCOMMIT
 2982: @cindex commands, TCOMMIT
 2983: 
 2984: Commits all pending transactions to the data files, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 2985: 
 2986: @emph{Syntax}
 2987: @example
 2988: TCOMMIT[@emph{:postcondition}]
 2989: @end example
 2990: 
 2991: @node THEN
 2992: @section THEN
 2993: @cindex THEN
 2994: @cindex commands, THEN
 2995: 
 2996: Saves the value of @code{$TEST} until the end of the current line, restoring it at the end of the current line or when a @code{QUIT} is encountered. @code{THEN} should be used in all new code in conjunction with @code{IF}.
 2997: 
 2998: @emph{Example}
 2999: @example
 3000: IF 1 THEN  WRITE "HELLO!",!
 3001: @end example
 3002: 
 3003: @node TROLLBACK
 3004: @section TROLLBACK
 3005: @cindex TROLLBACK
 3006: @cindex commands, TROLLBACK
 3007: 
 3008: Rolls back all pending transactions for the current process, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 3009: 
 3010: @emph{Syntax}
 3011: 
 3012: @example
 3013: TROLLBACK[@emph{:postcondition}]
 3014: @end example
 3015: 
 3016: @node TSTART
 3017: @section TSTART
 3018: @cindex TSTART
 3019: @cindex commands, TSTART
 3020: 
 3021: Introduces a new transaction level, incrementing @code{$TLEVEL}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted. Any global data file operations encountered when @code{$TLEVEL} is greater than zero will not be committed to the global data files until @code{TCOMMIT} is encountered.
 3022: 
 3023: If a transaction is restartable, variables in the @emph{variables-list} will be restored to their original values on a restart of the transaction.
 3024: 
 3025: @emph{Syntax}
 3026: 
 3027: @example
 3028: TSTART[@emph{:postcondition}] @emph{<variables-list>}:@emph{<transaction-parameters>}
 3029: @end example
 3030: 
 3031: @emph{<variables-list>} can be:
 3032: 
 3033: @table @asis
 3034: 
 3035: @item @code{()}
 3036: Do not save off any local variables. Makes the transaction non-restartable.
 3037: 
 3038: @item @code{*}
 3039: Save off all local variables. Makes the transaction restartable.
 3040: 
 3041: @item @code{@emph{variableName}}
 3042: Saves off only one local variable, @emph{variableName}. Makes the transaction restartable.
 3043: 
 3044: @item @code{(@emph{variableName1},...,@emph{variableNameN})}
 3045: Saves off all local variables listed. Makes the transaction restartable.
 3046: 
 3047: @end table
 3048: 
 3049: @emph{<transaction-parameters>} can be:
 3050: 
 3051: @table @asis
 3052: 
 3053: @item @code{S[ERIAL]}
 3054: Forces ACID properties on the transaction. When @code{SERIAL} is not selected, transactions occur in batch mode, and no attempt is made to guarantee ACID properties.
 3055: 
 3056: @item @code{T[RANSACTIONID]=@emph{transaction-id}}
 3057: Sets the ID of the transaction to @emph{transaction-id}
 3058: 
 3059: @end table
 3060: 
 3061: If you are using more than one transaction parameter, surround all of them in parentheses and separate them with commas, e.g.:
 3062: 
 3063: @example
 3064: TSTART (FOO,BAR):(SERIAL,TRANSACTIONID="FOO")
 3065: @end example
 3066: 
 3067: 
 3068: @node USE
 3069: @section USE
 3070: @cindex USE
 3071: @cindex commands, USE
 3072: 
 3073: Sets @code{$IO} to a particular FreeM I/O channel, allowing @code{READ}s from and @code{WRITE}s to the associated terminal, sequential file, or network socket. Also sets various device parameters.
 3074: 
 3075: @emph{Syntax (Terminal)}
 3076: 
 3077: @example
 3078:   USE@emph{:postcondition} @emph{io-channel}[:(@emph{right-margin}:@emph{input-field-length}:@emph{device-status-word}:@emph{position}:@emph{line-terminator}:@emph{break-key})]
 3079: @end example
 3080: 
 3081: For terminals, @emph{io-channel} must be 0.
 3082: 
 3083: Semantic and functional description of each device parameter TBA.
 3084: 
 3085: @emph{Syntax (Sequential Files)}
 3086: 
 3087: @example
 3088:   USE@emph{:postcondition} @emph{io-channel}[:@emph{seek-position}:@emph{terminator}:@emph{nodelay})]
 3089: @end example
 3090: 
 3091: For sequential files, @emph{io-channel} must be in the range 1-99.
 3092: 
 3093: Semantic and functional description of each device parameter TBA.
 3094: 
 3095: @emph{Syntax (Network Sockets)}
 3096: 
 3097: @example
 3098:   USE@emph{:postcondition} @emph{io-channel}
 3099: @end example
 3100: 
 3101: The above syntax will set @code{$IO} to @emph{io-channel}, directing successive @code{READ}s and @code{WRITE}s to @emph{io-channel}, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3102: 
 3103: @example
 3104:   USE@emph{:postcondition} @emph{io-channel}:/CONNECT
 3105: @end example
 3106: 
 3107: The above syntax will set @code{$IO} to @emph{io-channel}, as in the prior example, but will also attempt to connect to the host and port specified for @emph{io-channel} when it was @code{OPEN}ed. The @code{/CONNECT} control mnemonic is only valid for socket channels whose connection type is @code{TCP}. Using @code{/CONNECT} on a @code{UDP} socket channel will throw @code{SCKAERR} (error code 55).
 3108: 
 3109: For network sockets, @emph{io-channel} must be in the range 100-255.
 3110: 
 3111: @node VIEW
 3112: @section VIEW
 3113: @cindex VIEW
 3114: @cindex commands, VIEW
 3115: 
 3116: Provides write access to various FreeM internal parameters, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 3117: 
 3118: @emph{Syntax}
 3119: @example
 3120: VIEW[@emph{:postcondition}] @emph{view-number}[:@emph{view-argument}[:@emph{view-argument}...]]
 3121: @end example
 3122: 
 3123: The @emph{view-number} argument can be one of the following:
 3124: 
 3125: @table @asis
 3126: 
 3127: @item @code{21} - Close All Globals
 3128: Closes all global data files open in the current process. Takes no arguments.
 3129: 
 3130: @emph{Syntax}
 3131: @example
 3132: VIEW 21
 3133: @end example
 3134: 
 3135: @item @code{52} - Set G0 Input Translation Table for @code{$IO}
 3136: 
 3137: @emph{Syntax}
 3138: @example
 3139: VIEW 52:@emph{expr V trantab}
 3140: @end example
 3141: 
 3142: @item @code{53} - Set G0 Output Translation Table for @code{$IO}
 3143: 
 3144: @emph{Syntax}
 3145: @example
 3146: VIEW 53:@emph{expr V trantab}
 3147: @end example
 3148: 
 3149: @item @code{54} - Set G1 Input Translation Table for @code{$IO}
 3150: 
 3151: @emph{Syntax}
 3152: @example
 3153: VIEW 54:@emph{expr V trantab}
 3154: @end example
 3155: 
 3156: @item @code{55} - Set G1 Output Translation Table for @code{$IO}
 3157: 
 3158: @emph{Syntax}
 3159: @example
 3160: VIEW 55:@emph{expr V trantab}
 3161: @end example
 3162: 
 3163: @item @code{62} - Set @code{$RANDOM} Seed Number
 3164: Sets the seed number used by @code{$RANDOM} to @emph{numexpr}.
 3165: 
 3166: @emph{Syntax}
 3167: @example
 3168: VIEW 62:@emph{numexpr}
 3169: @end example
 3170: 
 3171: @item @code{63} - Set @code{$RANDOM} Parameter A
 3172: Sets the number used for @code{$RANDOM} Parameter A to @emph{numexpr}.
 3173: 
 3174: @emph{Syntax}
 3175: @example
 3176: VIEW 63:@emph{numexpr}
 3177: @end example
 3178: 
 3179: @item @code{64} - Set @code{$RANDOM} Parameter B
 3180: Sets the number used for @code{$RANDOM} Parameter B to @emph{numexpr}.
 3181: 
 3182: @emph{Syntax}
 3183: @example
 3184: VIEW 64:@emph{numexpr}
 3185: @end example
 3186: 
 3187: @item @code{65} - Set @code{$RANDOM} Parameter C
 3188: Sets the number used for @code{$RANDOM} Parameter C to @emph{numexpr}.
 3189: 
 3190: @emph{Syntax}
 3191: @example
 3192: VIEW 65:@emph{numexpr}
 3193: @end example
 3194: 
 3195: @item @code{66} - Set or Clear @code{SIGTERM} Handling Flag
 3196: Enables or disables handling of @code{SIGTERM} UNIX signals. If @emph{tvexpr} evaluates to 1 (@emph{true}), @code{SIGTERM} handling will be enabled. Otherwise, @code{SIGTERM} handling will be disabled.
 3197: 
 3198: @emph{Syntax}
 3199: @example
 3200: VIEW 66:@emph{tvexpr}
 3201: @end example
 3202: 
 3203: @item @code{67} - Set or Clear @code{SIGHUP} Handling Flag
 3204: Enables or disables handling of @code{SIGHUP} UNIX signals. If @emph{tvexpr} evaluates to 1 (@emph{true}), @code{SIGHUP} handling will be enabled. Otherwise, @code{SIGHUP} handling will be disabled.
 3205: 
 3206: @emph{Syntax}
 3207: @example
 3208: VIEW 67:@emph{tvexpr}
 3209: @end example
 3210: 
 3211: @item @code{70} - Set @code{$ZSORT}/@code{$ZSYNTAX} Flag
 3212: Selects whether @code{$ZS} resolves to @code{$ZSORT} or @code{$ZSYNTAX}.
 3213: 
 3214: If @emph{tvexpr} evaluates to @emph{true}, selects @code{$ZSYNTAX}. Otherwise, selects @code{$ZSORT}.
 3215: 
 3216: @emph{Syntax}
 3217: @example
 3218: VIEW 70:@emph{tvexpr}
 3219: @end example
 3220: 
 3221: @item @code{71} - Set @code{$ZNEXT}/@code{$ZNAME} Flag
 3222: Selects whether @code{$ZN} resolves to @code{$ZNEXT} or @code{$ZNAME}.
 3223: 
 3224: If @emph{tvexpr} evaluates to @emph{true}, selects @code{$ZNAME}. Otherwise, selects @code{$ZNEXT}.
 3225: 
 3226: @emph{Syntax}
 3227: @example
 3228: VIEW 71:@emph{tvexpr}
 3229: @end example
 3230: 
 3231: @item @code{72} - Set @code{$ZPREVIOUS}/@code{$ZPIECE} Flag
 3232: Selects whether @code{$ZP} resolves to @code{$ZPREVIOUS} or @code{$ZPIECE}.
 3233: 
 3234: If @emph{tvexpr} evaluates to @emph{true}, selects @code{$ZPIECE}. Otherwise, selects @code{$ZPREVIOUS}.
 3235: 
 3236: @emph{Syntax}
 3237: @example
 3238: VIEW 72:@emph{tvexpr}
 3239: @end example
 3240: 
 3241: @item @code{73} - Set @code{$ZDATA}/@code{$ZDATE} Flag
 3242: Selects whether @code{$ZD} resolves to @code{$ZDATA} or @code{$ZDATE}.
 3243: 
 3244: If @emph{tvexpr} evaluates to @emph{true}, selects @code{$ZDATE}. Otherwise, selects @code{$ZDATA}.
 3245: 
 3246: @emph{Syntax}
 3247: @example
 3248: VIEW 73:@emph{tvexpr}
 3249: @end example
 3250: 
 3251: @item @code{79} - Set Old @code{ZJOB} vs. New @code{ZJOB} Flag
 3252: If @emph{tvexpr} evaluates to @emph{true}, sets the @code{ZJOB} mode to new, otherwise, sets it to old.
 3253: 
 3254: @emph{Syntax}
 3255: @example
 3256: VIEW 79:@emph{tvexpr}
 3257: @end example
 3258: 
 3259: @item @code{80} - Set or Clear 8-Bit Flag
 3260: If @emph{tvexpr} evaluates to @emph{true}, sets FreeM to 8-bit mode. Otherwise, sets FreeM to 7-bit mode.
 3261: 
 3262: @emph{Syntax}
 3263: @example
 3264: VIEW 80:@emph{tvexpr}
 3265: @end example
 3266: 
 3267: @item @code{81} - Set or Clear PF1 Flag
 3268: If @emph{tvexpr} evaluates to @emph{true}, sets the @code{PF1} flag. We do not yet know what this does.
 3269: 
 3270: @emph{Syntax}
 3271: @example
 3272: VIEW 81:@emph{tvexpr}
 3273: @end example
 3274: 
 3275: @item @code{83} - Set or Clear Text in @code{$ZERROR} Flag
 3276: If @emph{tvexpr} evaluates to @emph{true}, descriptive error messages will be included in @code{$ZERROR}. Otherwise, only the short error code (i.e. @emph{ZILLFUN}) will be included in @code{$ZERROR}.
 3277: 
 3278: @emph{Syntax}
 3279: @example
 3280: VIEW 83:@emph{tvexpr}
 3281: @end example
 3282: 
 3283: @item @code{92} - Set Type Mismatch Error Flag on @code{EUR2DEM}
 3284: If @emph{tvexpr} evaluates to @emph{true}, a type mismatch error will be thrown in @code{EUR2DEM} currency conversions in certain situations that we do not yet understand.
 3285: 
 3286: @emph{Syntax}
 3287: @example
 3288: VIEW 92:@emph{tvexpr}
 3289: @end example
 3290: 
 3291: @item @code{93} - Define @code{ZKEY} Production Rule
 3292: We do not know what this does.
 3293: 
 3294: @item @code{96} - Set Global Prefix
 3295: Forces global data filenames to be prefixed with the result of @emph{expr}.
 3296: 
 3297: @emph{Syntax}
 3298: @example
 3299: VIEW 96:@emph{expr V string}
 3300: @end example
 3301: 
 3302: @item @code{97} - Set Global Postfix
 3303: Forces global data filenames to be postfixed with the result of @emph{expr}.
 3304: 
 3305: @emph{Syntax}
 3306: @example
 3307: VIEW 97:@emph{expr V string}
 3308: @end example
 3309: 
 3310: @item @code{98} - Set Routine Extension
 3311: Sets the default extension for M routine filenames to the result of @emph{expr}.
 3312: 
 3313: @emph{Syntax}
 3314: @example
 3315: VIEW 98:@emph{expr V string}
 3316: @end example
 3317: 
 3318: @item @code{101} - Set @code{ierr}
 3319: Sets the FreeM internal @code{ierr} value to @emph{intexpr}. Used by some FreeM polyfills (commands or functions implemented in M code).
 3320: 
 3321: @emph{Syntax}
 3322: @example
 3323: VIEW 101:@emph{intexpr}
 3324: @end example
 3325: 
 3326: @item @code{102} - Set @code{ierr} (Deferred)
 3327: Sets the FreeM internal @code{ierr} value to @emph{intexpr}, but only after the current process stack level is exited. Used by FreeM polyfills to throw an error that will appear to come from the user's own code rather than the polyfill implementation M code.
 3328: 
 3329: @emph{Syntax}
 3330: @example
 3331: VIEW 102:@emph{intexpr}
 3332: @end example
 3333: 
 3334: @item @code{103} - Signal @code{MERGE} to @code{^$WINDOW} Complete
 3335: Signals FreeM's MWAPI implementation that a @code{MERGE} to @code{^$WINDOW} or descendant subscripts thereof has completed.
 3336: 
 3337: @emph{Syntax}
 3338: @example
 3339: VIEW 103[@emph{:subscript}]
 3340: @end example
 3341: 
 3342: @item @code{110} - Set Local @code{$ORDER}/@code{$QUERY} Data Value
 3343: Sets the local variable @code{$ORDER}/@code{$QUERY} data value to the result of @emph{expr}. We're not entirely sure what this is.
 3344: 
 3345: @emph{Syntax}
 3346: @example
 3347: VIEW 110:@emph{expr}
 3348: @end example
 3349: 
 3350: @item @code{111} - Set Global @code{$ORDER}/@code{$QUERY} Data Value
 3351: Sets the global variable @code{$ORDER}/@code{$QUERY} data value to the result of @emph{expr}. We're not entirely sure what this is.
 3352: 
 3353: @emph{Syntax}
 3354: @example
 3355: VIEW 111:@emph{expr}
 3356: @end example
 3357: 
 3358: @item @code{113} - Set @code{termio} Information
 3359: We don't know what this does.
 3360: 
 3361: @item @code{133} - Remember @code{ZLOAD} Directory on @code{ZSAVE}
 3362: We don't know what this does, but it takes a @emph{tvexpr}.
 3363: 
 3364: @emph{Syntax}
 3365: @example
 3366: VIEW 133:@emph{tvexpr}
 3367: @end example
 3368: 
 3369: @end table
 3370: 
 3371: 
 3372: 
 3373: @node WRITE
 3374: @section WRITE
 3375: @cindex WRITE
 3376: @cindex commands, WRITE
 3377: 
 3378: @node XECUTE
 3379: @section XECUTE
 3380: @cindex XECUTE
 3381: @cindex commands, XECUTE
 3382: 
 3383: @node ZASSERT
 3384: @section ZASSERT
 3385: @cindex ZASSERT
 3386: @cindex commands, ZASSERT
 3387: @cindex commands, debugging
 3388: @cindex commands, implementation-specific
 3389: @cindex commands, non-standard
 3390: @emph{FreeM Extension}
 3391: 
 3392: Triggers error @code{ZASSERT} if the supplied truth-valued expression @emph{tvexpr} is @emph{false} (@emph{1} is @emph{true}, and @emph{0} is @emph{false}), and that the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 3393: 
 3394: The @code{ZASSERT} error is catchable whether using standard-style, FreeM-style, or DSM 2.0-style error processing.
 3395: 
 3396: @emph{Syntax}
 3397: 
 3398: @example
 3399:  ZASSERT@emph{:postcondition} @emph{<tvexpr>}
 3400: @end example
 3401: 
 3402: @emph{Example}
 3403: 
 3404: @example
 3405: DEFAULT.USER> SET DEBUG=1
 3406: 
 3407: 
 3408: DEFAULT.USER> ZASSERT:DEBUG 1=1
 3409: 
 3410: 
 3411: DEFAULT.USER> ZASSERT:DEBUG 1=0
 3412:  
 3413:  
 3414: >> Error ZASSERT:  programmer assertion failed in SYSTEM::^%SYSINIT  [$STACK = 0]
 3415: >> ZASSERT:DEBUG 1=0
 3416:                    ^
 3417: @end example
 3418: 
 3419: @node ZBREAK
 3420: @section ZBREAK
 3421: @cindex ZBREAK
 3422: @cindex commands, ZBREAK
 3423: @cindex commands, debugging
 3424: @cindex commands, implementation-specific
 3425: @cindex commands, non-standard
 3426: @emph{FreeM Extension}
 3427: 
 3428: Sets or clears the @code{ZBREAK} flag@footnote{NOTE: FreeM team needs to investigate how @code{zbreakon} and @code{zbflag} affect program execution.}, based on the result of evaluating @emph{tvexpr}.
 3429: 
 3430: @emph{Syntax}
 3431: 
 3432: @example
 3433: ZBREAK @emph{tvexpr}
 3434: @end example
 3435: 
 3436: @node ZCONST
 3437: @section ZCONST
 3438: @cindex ZCONST
 3439: @cindex commands, ZCONST
 3440: @cindex commands, non-standard
 3441: @emph{FreeM Extension}
 3442: 
 3443: Defines a local @emph{constant}, or variable that cannot be altered after its initial definition, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3444: 
 3445: Constants must only be locals, and globals are not supported.
 3446: 
 3447: @emph{Syntax}
 3448: 
 3449: @example
 3450: @code{ZCONST@emph{:postcondition} @emph{mref1}=@emph{initial-value1},...,@emph{mrefN}=@emph{initial-valueN}}
 3451: @end example
 3452: 
 3453: @node ZEDIT
 3454: @section ZEDIT
 3455: @cindex ZEDIT
 3456: @cindex commands, ZEDIT
 3457: @cindex commands, non-standard
 3458: @emph{FreeM Extension}
 3459: 
 3460: Edits a routine using an external editor. Uses environment variable @code{$EDITOR} if defined; otherwise, uses @code{vi}.
 3461: 
 3462: @emph{Syntax}
 3463: 
 3464: @example
 3465: ZEDIT@emph{[:postcondition]}
 3466: @end example
 3467: 
 3468: In its argumentless form, edits the currently-active routine, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3469: 
 3470: @emph{Syntax}
 3471: 
 3472: @example
 3473: ZEDIT@emph{[:postcondition]} @emph{<routine-name>}
 3474: @end example
 3475: 
 3476: In its single-argument form, edits @emph{<routine-name>}, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3477: 
 3478: Routine names must not be quoted, and must not included a leading caret (@code{^}).
 3479: 
 3480: @emph{Errors}
 3481: 
 3482: @code{ZEDIT} will raise @code{ZNOPGM} if the routine cannot be found, or there is no routine currently loaded in argumentless form.
 3483: 
 3484: @node ZGOTO
 3485: @section ZGOTO
 3486: @cindex ZGOTO
 3487: @cindex commands, ZGOTO
 3488: @cindex commands, implementation-specific
 3489: @cindex commands, non-standard
 3490: @emph{FreeM Extension}
 3491: 
 3492: In its single-argument form, enables @code{BREAK} mode and branches unconditionally to @emph{entryref}.
 3493: 
 3494: @emph{Syntax}
 3495: 
 3496: @example
 3497: ZGOTO @emph{entryref}
 3498: @end example
 3499: 
 3500: In its argumentless form, resumes execution after a @code{BREAK}.
 3501: 
 3502: @emph{Syntax}
 3503: 
 3504: @example
 3505: ZGOTO
 3506: @end example
 3507: 
 3508: @node ZHALT
 3509: @section ZHALT
 3510: @cindex ZHALT
 3511: @cindex commands, ZHALT
 3512: @cindex commands, implementation-specific
 3513: @cindex commands, non-standard
 3514: @emph{FreeM Extension}
 3515: 
 3516: In its single-argumented form, @code{ZHALT} command is used to exit the FreeM process with a specific return value @emph{intexpr}.
 3517: 
 3518: @emph{Syntax}
 3519: 
 3520: @example
 3521: ZHALT @emph{intexpr}
 3522: @end example
 3523: 
 3524: In its argumentless form, @code{ZHALT} is synonymous with @code{HALT}.
 3525: 
 3526: @emph{Syntax}
 3527: 
 3528: @example
 3529: ZHALT
 3530: @end example
 3531: 
 3532: @node ZINSERT
 3533: @section ZINSERT
 3534: @cindex ZINSERT
 3535: @cindex commands, ZINSERT
 3536: @cindex commands, implementation-specific
 3537: @cindex commands, non-standard
 3538: @emph{FreeM Extension}
 3539: 
 3540: Inserts a line of M code into the currently-active routine buffer, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3541: 
 3542: @emph{Syntax}
 3543: 
 3544: @example
 3545: ZINSERT@emph{:postcondition} @emph{expr V mcode}[:@emph{label}]
 3546: @end example
 3547: 
 3548: Above, @emph{expr V mcode} is an expression returning a string giving M code. If @emph{label} is omitted, the code will be inserted at the insertion point, which is typically the end of the routine. Otherwise, the code will be inserted at the line immediately following @emph{label}.
 3549: 
 3550: @node ZJOB
 3551: @section ZJOB
 3552: @cindex ZJOB
 3553: @cindex commands, ZJOB
 3554: @cindex commands, implementation-specific
 3555: @cindex commands, non-standard
 3556: @emph{FreeM Extension}
 3557: 
 3558: When @code{ZJOB} is used, the semantics are identical to @code{JOB}, with the exception that the @emph{timeout} is forced to be @code{0}, regardless of what the user specifies.
 3559: 
 3560: For more information, see @code{JOB}.
 3561: 
 3562: @node ZLOAD
 3563: @section ZLOAD
 3564: @cindex ZLOAD
 3565: @cindex commands, ZLOAD
 3566: @cindex commands, implementation-specific
 3567: @cindex commands, non-standard
 3568: @emph{FreeM Extension}
 3569: 
 3570: Loads routine @emph{<routine-name>} into FreeM's routine buffer, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3571: 
 3572: @emph{Syntax}
 3573: 
 3574: @example
 3575: ZLOAD@emph{:postcondition} @emph{<routine-name>}
 3576: @end example
 3577: 
 3578: 
 3579: @node ZMAP
 3580: @section ZMAP
 3581: @cindex ZMAP
 3582: @cindex commands, ZMAP
 3583: @cindex commands, implementation-specific
 3584: @cindex commands, non-standard
 3585: 
 3586: Maps global name @code{gvn} to be mapped to the non-default namespace @emph{expr V namespace}, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 3587: 
 3588: @emph{Syntax}
 3589: 
 3590: @example
 3591: ZMAP[@emph{:postcondition}] GLOBAL @emph{gvn}=@emph{expr V namespace}
 3592: @end example
 3593: 
 3594: @node ZNEW
 3595: @section ZNEW
 3596: @cindex ZNEW
 3597: @cindex commands, ZNEW
 3598: @cindex commands, implementation-specific
 3599: @cindex commands, non-standard
 3600: @emph{FreeM Extension}
 3601: 
 3602: @node ZPRINT
 3603: @section ZPRINT
 3604: @cindex ZPRINT
 3605: @cindex commands, ZPRINT
 3606: @cindex commands, implementation-specific
 3607: @cindex commands, non-standard
 3608: @emph{FreeM Extension}
 3609: 
 3610: In argumentless form, prints the contents of the current routine buffer, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3611: 
 3612: @emph{Syntax}
 3613: 
 3614: @example
 3615: ZPRINT@emph{:postcondition}
 3616: @end example
 3617: 
 3618: In argumented form, prints a subset of the current routine buffer, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3619: 
 3620: @emph{Syntax}
 3621: 
 3622: @example
 3623: ZPRINT@emph{:postcondition} @emph{start}[:@emph{end}]
 3624: @end example
 3625: 
 3626: In the above syntax, @emph{start} and @emph{end} can be a tag in the current routine, or @code{*} to indicate the routine buffer insertion point (typically the end of the routine).
 3627: 
 3628: @node ZQUIT
 3629: @section ZQUIT
 3630: @cindex ZQUIT
 3631: @cindex commands, ZQUIT
 3632: @cindex commands, implementation-specific
 3633: @cindex commands, non-standard
 3634: @emph{FreeM Extension}
 3635: 
 3636: In its single-argument form, quits from @emph{levels} levels of the stack, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3637: 
 3638: In its argumentless form, quits from @code{$STACK} levels of the stack, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3639: 
 3640: @emph{Syntax}
 3641: 
 3642: @example
 3643: @code{ZQUIT@emph{:postcondition} [@emph{levels}]}
 3644: @end example
 3645: 
 3646: @node ZREMOVE
 3647: @section ZREMOVE
 3648: @cindex ZREMOVE
 3649: @cindex commands, ZREMOVE
 3650: @cindex commands, implementation-specific
 3651: @cindex commands, non-standard
 3652: @emph{FreeM Extension}
 3653: 
 3654: In argumentless form, removes all M code from the current routine buffer, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3655: 
 3656: @emph{Syntax}
 3657: 
 3658: @example
 3659: ZREMOVE@emph{:postcondition}
 3660: @end example
 3661: 
 3662: In argumented form, removes a subset of the current routine buffer, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3663: 
 3664: @emph{Syntax}
 3665: 
 3666: @example
 3667: ZREMOVE@emph{:postcondition} @emph{start}[:@emph{end}]
 3668: @end example
 3669: 
 3670: In the above syntax, @emph{start} and @emph{end} can be a tag in the current routine, or @code{*} to indicate the routine buffer insertion point (typically the end of the routine).
 3671: 
 3672: @node ZSAVE
 3673: @section ZSAVE
 3674: @cindex ZSAVE
 3675: @cindex commands, ZSAVE
 3676: @cindex commands, implementation-specific
 3677: @cindex commands, non-standard
 3678: @emph{FreeM Extension}
 3679: 
 3680: 
 3681: @node ZTHROW
 3682: @section ZTHROW
 3683: @cindex ZTHROW
 3684: @cindex commands, ZTHROW
 3685: @cindex commands, non-standard
 3686: @emph{FreeM Extension}
 3687: 
 3688: Raises an error condition as long as the optional @emph{postcondition} is @emph{true} or omitted.
 3689: 
 3690: @emph{Syntax}
 3691: 
 3692: @example
 3693: @code{ZTHROW@emph{:postcondition} @emph{expr V error-code}}
 3694: @end example
 3695: 
 3696: @emph{Example}
 3697: 
 3698: @example
 3699: @code{ZTHROW "M102"}
 3700: @end example
 3701: 
 3702: @node ZTRAP
 3703: @section ZTRAP
 3704: @cindex ZTRAP
 3705: @cindex commands, ZTRAP
 3706: @cindex commands, debugging
 3707: @cindex commands, implementation-specific
 3708: @cindex commands, non-standard
 3709: @emph{FreeM Extension}
 3710: 
 3711: Synonymous with @ref{ZTHROW}.
 3712: 
 3713: @node ZUNMAP
 3714: @section ZUNMAP
 3715: @cindex ZUNMAP
 3716: @cindex commands, ZUNMAP
 3717: @cindex commands, implementation-specific
 3718: @cindex commands, non-standard
 3719: 
 3720: Removes any mapping connecting @emph{gvn} to a non-default namespace, provided the optional @emph{postcondition} evaluates to @emph{true} or is omitted.
 3721: 
 3722: @emph{Syntax}
 3723: 
 3724: @example
 3725: ZUNMAP GLOBAL @emph{gvn}
 3726: @end example
 3727: 
 3728: @node ZWATCH
 3729: @section ZWATCH
 3730: @cindex ZWATCH
 3731: @cindex commands, ZWATCH
 3732: @cindex commands, debugging
 3733: @cindex commands, implementation-specific
 3734: @cindex commands, non-standard
 3735: @emph{FreeM Extension}
 3736: 
 3737: Sets a watchpoint on a global, local, or SSVN node.
 3738: 
 3739: @emph{Syntax}
 3740: 
 3741: 
 3742: In its @emph{argumentless} form, @code{ZWATCH} toggles watchpoints on and off, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3743: 
 3744: @example
 3745: ZWATCH[@emph{:postcondition}]
 3746: @end example
 3747: 
 3748: In its @emph{inclusive} form, @code{ZWATCH} adds, removes, or examines watchpoints, provided the optional @emph{postcondition} is @emph{true} or omitted.
 3749: 
 3750: A @code{+} adds a new watchpoint to the following variable.
 3751: 
 3752: A @code{-} removes an existing watchpoint for the following variable.
 3753: 
 3754: A @code{?} examines the status of a watchpoint for the following variable.
 3755: 
 3756: @example
 3757: ZWATCH[@emph{:postcondition}] [+|-|?]@emph{var1}...,[+|-|?]@emph{varN}
 3758: @end example
 3759: 
 3760: 
 3761: The following example demonstrates turning watchpoint processing on and adding a watchpoint for global variable @code{^snw(1)}. It then changes the value of @code{^snw(1)}.
 3762: 
 3763: @example
 3764: DEFAULT.USER> ZWATCH
 3765:  
 3766: Watchpoints enabled.
 3767:  
 3768: DEFAULT.USER> ZWATCH +^SNW(1)
 3769:  
 3770: Added '^SNW("1")' to the watchlist.
 3771:  
 3772: DEFAULT.USER> SET ^SNW(1)="new value"
 3773:  
 3774: >> WATCHPOINT:  ^SNW("1") => 'new value' (changed 1 times)
 3775: 
 3776: @end example
 3777: 
 3778: The following example will remove that watchpoint:
 3779: 
 3780: @example
 3781: DEFAULT.USER> ZWATCH -^SNW(1)
 3782:  
 3783: Removed '^SNW("1")' from the watchlist.
 3784:  
 3785: DEFAULT.USER> ZWATCH ?^SNW(1)
 3786:  
 3787: '^SNW("1")' is not being watched.
 3788: @end example
 3789: 
 3790: @node ZWITH
 3791: @section ZWITH
 3792: @cindex ZWITH
 3793: @cindex commands, ZWITH
 3794: @cindex commands, non-standard
 3795: @emph{FreeM Extension}
 3796: 
 3797: NOTE: This command may be deprecated and removed in future FreeM releases.
 3798: 
 3799: Sets a prefix to be applied to all subsequent local variable or constant references.
 3800: 
 3801: @emph{Syntax}
 3802: 
 3803: @example
 3804: @code{ZWITH@emph{:postcondition} @emph{var-prefix}}
 3805: @end example
 3806: 
 3807: In the above single-argument form, sets the @code{$WITH} prefix to @emph{var-prefix}, provided that the optional @emph{postcondition} is either @emph{true} or omitted.
 3808: 
 3809: The @emph{var-prefix} argument may be a string literal or any valid FreeM expression.
 3810: 
 3811: @example
 3812: @code{ZWITH@emph{:postcondition}}
 3813: @end example
 3814: 
 3815: In the above argumentless form, clears the @code{$WITH} prefix, provided the optional @emph{postcondition} is either @emph{true} or omitted. Equivalent to @code{ZWITH ""}.
 3816: 
 3817: 
 3818: 
 3819: 
 3820: 
 3821: 
 3822: 
 3823: 
 3824: @node ZWRITE
 3825: @section ZWRITE
 3826: @cindex ZWRITE
 3827: @cindex commands, ZWRITE
 3828: @cindex commands, implementation-specific
 3829: @cindex commands, non-standard
 3830: @emph{FreeM Extension}
 3831: 
 3832: Writes the names and values of M variables to @code{$IO}.
 3833: 
 3834: @emph{Syntax}
 3835: 
 3836: @example
 3837: ZWRITE@emph{:postcondition}
 3838: @end example
 3839: 
 3840: In the argumentless form, writes the names and values of all local variables to @code{$IO} if the optional @emph{postcondition} is @emph{true} or omitted.
 3841: 
 3842: @example
 3843: ZWRITE@emph{:postcondition} @emph{ArrayName},@dots{}
 3844: @end example
 3845: 
 3846: In the inclusive form, writes the names and values of all local, global, or structured system variables specified in the list of @emph{ArrayName}s to @code{$IO} if the optional @emph{postcondition} is @emph{true} or omitted.
 3847: 
 3848: @example
 3849: ZWRITE@emph{:postcondition} (@emph{ArrayName},@dots{})
 3850: @end example
 3851: 
 3852: In the exclusive form, writes all local variables @emph{except} those specified in the list of @emph{ArrayName}s to @code{$IO} if the optional @emph{postcondition} is @emph{true} or omitted.
 3853: 
 3854: 
 3855: @node Structured System Variables
 3856: @chapter Structured System Variables
 3857: @cindex variables, structured system
 3858: @cindex structured system variables
 3859: @cindex SSVNs
 3860: 
 3861: @menu
 3862: * ^$CHARACTER::                         Character set information.
 3863: * ^$DEVICE::                            Device information.
 3864: * ^$DISPLAY::                           Information about graphic display.
 3865: * ^$EVENT::                             Information supplied about a synchronous or asynchronous event.
 3866: * ^$GLOBAL::                            Information about M globals.
 3867: * ^$JOB::                               Information about and control of FreeM jobs.
 3868: * ^$LOCK::                              Information about the FreeM lock table.
 3869: * ^$OBJECT::                            Information about FreeM objects.
 3870: * ^$ROUTINE::                           Information about FreeM routines.
 3871: * ^$SYSTEM::                            Information about the running system.
 3872: * ^$WINDOW::                            Configuration of MWAPI windows.
 3873: * ^$ZPROCESS::                          Information about and control of system processes.
 3874: * ^$ZRPI::                              Information about and control of Raspberry Pi GPIO pins.
 3875: @end menu
 3876: 
 3877: SSVN subscripts are each described in the following format:
 3878: 
 3879: @table @asis
 3880: @item @code{@emph{<ssvn-subscript-name>}} +/-R +/-U +/-D
 3881: @end table
 3882: 
 3883: The R, U, and D flags represent Read, Update, and Delete. A minus sign indicates that the given operation is @emph{not} allowed, and a plus sign indicates that the given operation @emph{is} allowed.
 3884: 
 3885: @node ^$CHARACTER
 3886: @section ^$CHARACTER
 3887: @cindex ^$CHARACTER
 3888: @cindex structured system variables, ^$CHARACTER
 3889: 
 3890: Exposes character set information. As FreeM currently only supports the @code{M} character set, the first subscript of @code{^$CHARACTER} must always be @code{"M"}.
 3891: 
 3892: The following values for the second subscript are supported:
 3893: 
 3894: @table @asis
 3895: 
 3896: @item @code{IDENT} +R -U -D
 3897: Returns the empty string.
 3898: 
 3899: @item @code{COLLATE} +R -U -D
 3900: Returns the empty string.
 3901: 
 3902: @item @code{INPUT} +R -U -D
 3903: Returns the empty string if the third subscript is @code{M}, otherwise, raises error @code{M38}.
 3904: 
 3905: @item @code{OUTPUT} +R -U -D
 3906: Returns the empty string if the third subscript is @code{M}, otherwise, raises error @code{M38}.
 3907: 
 3908: @end table
 3909: 
 3910: @node ^$DEVICE
 3911: @section ^$DEVICE
 3912: @cindex ^$DEVICE
 3913: @cindex structured system variables, ^$DEVICE
 3914: 
 3915: FreeM implements several important pieces of functionality in the @code{^$DEVICE} SSVN.
 3916: 
 3917: The first subscript of @code{^$DEVICE} represents the I/O channel of an @code{OPEN}ed device.
 3918: 
 3919: The following values for the second subscript are supported:
 3920: 
 3921: @table @asis
 3922: 
 3923: @item @code{$DEVICE}
 3924: Returns the value of @code{$DEVICE} for the specified I/O channel.
 3925: 
 3926: @item @code{$X} +R -U -D
 3927: Returns the horizontal cursor position of a terminal device. Only valid if the I/O channel is @code{0}.
 3928: 
 3929: @item @code{$Y} +R -U -D
 3930: Returns the vertical cursor position of a terminal device. Only valid if the I/O channel is @code{0}.
 3931: 
 3932: @item @code{ROWS} +R -U -D
 3933: Returns the number of character rows on the terminal device. Only valid if the I/O channel is @code{0}.
 3934: 
 3935: @item @code{COLUMNS} +R -U -D
 3936: Returns the number of character columns on the terminal device. Only valid if the I/O channel is @code{0}.
 3937: 
 3938: @item @code{CHARACTER} +R -U -D
 3939: Returns the character set of the specified I/O channel; always @code{M} in the current implementation.
 3940: 
 3941: @item @code{INPUT_BUFFER} +R +U -D
 3942: Returns or sets the contents of the input buffer for the specified I/O channel. Data populated in this node will remain in the buffer until subsequent @code{READ} command(s) remove it. This can be used to perform input buffer stuffing, i.e., to fill out an interactive form programmatically.
 3943: 
 3944: @item @code{NAME} +R -U -D
 3945: Returns the operating system's name for the file, device, or socket attached to the specified I/O channel.
 3946: 
 3947: @item @code{FD} +R -U -D
 3948: Returns the UNIX file descriptor of the specified I/O channel.
 3949: 
 3950: @item @code{MODE} +R -U -D
 3951: Returns one of @code{READ}, @code{WRITE}, @code{READWRITE}, or @code{APPEND}, depending on the mode in which the specified I/O channel was opened.
 3952: 
 3953: @item @code{EOF} +R -U -D
 3954: Returns @code{1} if the I/O channel has encountered an end-of-file condition; @code{0} otherwise. Only valid if the I/O channel is connected to a sequential file.
 3955: 
 3956: @item @code{LENGTH} +R -U -D
 3957: Returns the length of the file connected to the I/O channel. Only valid if the I/O channel is connected to a sequential file.
 3958: 
 3959: @item @code{NAMESPACE} +R -U -D
 3960: Returns the current @emph{mnemonic-space} in use for the referenced I/O channel. Always @code{X364} for terminals and blank for sequential files.
 3961: 
 3962: @item @code{TYPE} +R -U -D
 3963: Returns either @code{1,FILE}, @code{2,SOCKET}, or @code{4,TERMINAL}, depending on the device type associated with the specified I/O channel.
 3964: 
 3965: @item @code{OPTIONS} -R -U -D
 3966: The following subscripts reside beneath @code{^$DEVICE(<io-channel>,"OPTIONS")}, and this subscript may not be accessed without one of the following third-level subscripts being specified:
 3967: 
 3968: @table @asis
 3969: 
 3970: @item @code{DSW} +R +U -D
 3971: Sets or returns the current @emph{Device Status Word} controlling terminal characteristics. Only valid for I/O channel 0.
 3972: 
 3973: @item @code{TERMINATOR} +R +U -D
 3974: Sets or returns the @code{READ} terminator for the specified I/O channel. Must be either @code{$C(13,10)} or @code{$C(10)}. Currently only supported for socket devices (those having an I/O channel of 100-255).
 3975: 
 3976: @item @code{TERMID} +R -U -D
 3977: Returns the type of terminal connected to channel 0. Only valid for I/O channel 0.
 3978: 
 3979: @item @code{ECHO} +R +U -D
 3980: Enables or disables local echo of characters typed in a @code{READ} command. Only valid for I/O channel 0. Corresponds to bit 0 of the Device Status Word.
 3981: 
 3982: @item @code{DELMODE} +R +U -D
 3983: Enables or disables visual backspace during a @code{READ} command. Only valid for I/O channel 0. Corresponds to bit 2 of the Device Status Word.
 3984: 
 3985: @item @code{ESCAPE} +R +U -D
 3986: Enables or disables escape sequence processing during a @code{READ} command. Only valid for I/O channel 0. Corresponds to bit 6 of the Device Status Word.
 3987: 
 3988: @item @code{CONVUPPER} +R +U -D
 3989: Enables or disables automatic conversion to uppercase of alphabetical characters during a @code{READ} command. Only valid for I/O channel 0. Corresponds to bit 14 of the Device Status Word.
 3990: 
 3991: @item @code{DELEMPTY} +R +U -D
 3992: Enables or disables the automatic deletion of empty strings supplied to a @code{READ} command. Only valid for I/O channel 0. Corresponds to bit 19 of the Device Status Word.
 3993: 
 3994: @item @code{NOCTRLS} +R +U -D
 3995: TBD. Only valid for I/O channel 0. Corresponds to bit 20 of the Device Status Word.
 3996: 
 3997: @item @code{CTRLOPROC} +R +U -D
 3998: Enables or disables @emph{Ctrl-O} processing during @code{READ} commands. Only valid for I/O channel 0. Corresponds to bit 21 of the Device Status Word.
 3999: 
 4000: @item @code{NOTYPEAHEAD} +R +U -D
 4001: Enables or disables typeahead buffering during @code{READ} commands. Only valid for I/O channel 0. Corresponds to bit 25 of the Device Status Word.
 4002: @end table
 4003: @end table
 4004: 
 4005: @emph{Example}
 4006: 
 4007: The following example M code opens @code{/etc/freem.conf} and reads its contents line-by-line until the end of the file is reached.
 4008: 
 4009: @example
 4010:  SET ^$JOB($JOB,"IOPATH")="/etc"   ; set I/O path to /etc
 4011:  OPEN 1:"freem.conf/r" ; open freem.conf for reading
 4012:  ;
 4013:  ; read until we run out of lines
 4014:  ;
 4015:  FOR  USE 1 READ LINE USE 0 QUIT:^$DEVICE(1,"EOF")  D
 4016:  . WRITE LINE,!
 4017:  ;
 4018:  CLOSE 1
 4019:  QUIT
 4020: @end example
 4021: 
 4022: @node ^$DISPLAY
 4023: @section ^$DISPLAY
 4024: @cindex ^$DISPLAY
 4025: @cindex structured system variables, ^$DISPLAY
 4026: 
 4027: Provides information about the specified graphical display. The first subscript corresponds to a display number, which is an integer value, often corresponding to the current value of the @code{$PDISPLAY} ISV.
 4028: 
 4029: The following second-level subscripts and specified descendant subscripts are supported:
 4030: 
 4031: @table @asis
 4032: 
 4033: @item @code{CLIPBOARD} +R +U +D
 4034: Retrieves, sets, or erases the contents of the system clipboard.
 4035: 
 4036: @item @code{PLATFORM} +R -U -D
 4037: Retrieves the name and version of the underlying window system platform.
 4038: 
 4039: @item @code{SIZE} +R -U -D
 4040: Retrieves the display resolution of the specified graphical display. For instance, a 1080p display would have a @code{SIZE} value of @code{1920,1080}.
 4041: 
 4042: @item @code{SPECTRUM} +R -U -D
 4043: Retrieves the color depth (number of colors supported) of the specified graphical display.
 4044: 
 4045: @item @code{COLORTYPE} +R -U -D
 4046: Always returns @code{COLOR}, as monochrome and grayscale displays are not yet supported in FreeM.
 4047: 
 4048: @item @code{UNITS} +R -U -D
 4049: Returns the measurement unit of the specified display, i.e., @code{PIXEL}.
 4050: 
 4051: @item @code{TYPEFACE} +R -U -D
 4052: The third-level subscripts beneath this subscript represent a list of font families available on this display. The fourth level subscript is a list of sizes supported for the specified typeface, or @code{0} for vector typefaces, such as TrueType, OpenType, and Adobe Type 1 fonts.
 4053: 
 4054: @end table
 4055: 
 4056: @node ^$EVENT
 4057: @section ^$EVENT
 4058: @cindex ^$EVENT
 4059: @cindex structured system variables, ^$EVENT
 4060: 
 4061: The @code{^$EVENT} SSVN is not yet implemented.
 4062: 
 4063: @node ^$GLOBAL
 4064: @section ^$GLOBAL
 4065: @cindex ^$GLOBAL
 4066: @cindex structured system variables, ^$GLOBAL
 4067: 
 4068: The @code{^$GLOBAL} structured system variable provides information about M globals. The first-level subscript is a global name, sans the leading caret symbol.
 4069: 
 4070: The following second-level subscripts are supported:
 4071: 
 4072: @table @asis
 4073: 
 4074: @item @code{BYTES} +R -U -D
 4075: Returns the number of bytes this global occupies in fixed storage.
 4076: 
 4077: @item @code{BLOCKS} +R -U -D
 4078: Returns the number of blocks contained in this global.
 4079: 
 4080: @item @code{BLOCKSIZE} +R -U -D
 4081: Returns the size of data blocks for this global. Currently, FreeM only supports 1024-byte blocks.
 4082: 
 4083: @item @code{FILE} +R -U -D
 4084: Returns the full filesystem path to the data file where this global resides in fixed storage.
 4085: 
 4086: @item @code{NAMESPACE} +R +U +D
 4087: Returns or sets the name of the FreeM namespace to which this global belongs. @code{SET}ting this node creates a mapping for the specified global name to a non-default namespace. @code{KILL}ing this node restores the mapping configuration for the specified global to the default.
 4088: 
 4089: @end table
 4090: 
 4091: @node ^$JOB
 4092: @section ^$JOB
 4093: @cindex ^$JOB
 4094: @cindex structured system variables, ^$JOB
 4095: 
 4096: FreeM fully implements @code{^$JOB} per ANSI X11.1-1995, as well as several extensions proposed in the M Millennium Draft Standard.
 4097: 
 4098: The first subscript of @code{^$JOB} represents the @code{$JOB} of the process.
 4099: 
 4100: If you @code{KILL} a first-level subscript of @code{^$JOB}, the @code{SIGTERM} signal will be sent to the corresponding UNIX process, causing pending transactions to be rolled back and the process to be terminated. If the targeted process is in direct mode, the user will be prompted with options of either rolling back or committing any pending transactions.
 4101: 
 4102: The following subscripts are supported:
 4103: 
 4104: @table @asis
 4105: 
 4106: @item @code{GVNDEFAULT} +R +U +D
 4107: Contains a default expression to be evaluated if a global variable access attempt results in an @code{M7} error.
 4108: 
 4109: Equivalent to wrapping all global accesses in @code{$GET(@emph{global-name},@emph{string-expr})}.
 4110: 
 4111: @item @code{LVNDEFAULT} +R +U +D
 4112: Contains a default expression to be evaluated if a local variable access attempt results in an @code{M6} error.
 4113: 
 4114: Equivalent to wrapping all local accesses in @code{$GET(@emph{global-name},@emph{string-expr})}.
 4115: 
 4116: @item @code{LVNQOVAL} +R +U +D
 4117: Contains the data value (if any) at the subscripted local variable reference from the most recent @code{$ORDER} or @code{$QUERY} operation.
 4118: 
 4119: This node is useful for code that uses @code{$ORDER} or @code{$QUERY} heavily in loops that retrieve successive data values, as it will prevent an additional symbol table scan that would result from retrieving the data value in the usual way, thus improving application performance. However, this optimization comes at the cost of compatibility with other M implementations.
 4120: 
 4121: @item @code{GVNQOVAL} +R +U +D
 4122: Contains the data value (if any) at the subscripted global variable reference from the most recent @code{$ORDER} or @code{$QUERY} operation.
 4123: 
 4124: This node is useful for code that uses @code{$ORDER} or @code{$QUERY} heavily in loops that retrieve successive data values, as it will prevent an additional data file scan that would result from retrieving the data value in the usual way, thus improving application performance. However, this optimization comes at the cost of compatibility with other M implementations.
 4125: 
 4126: @item @code{ZCOMMANDS} +R +U -D
 4127: Contains a space-delimited list of @code{Z}-commands to be treated as intrinsic. Any @code{Z}-command not appearing in this list will be treated as a user-defined command.
 4128: 
 4129: For instance, if command @code{ZFOO} does @emph{not} appear in this list, FreeM will attempt to run @code{^%ZFOO} as a subroutine when the @code{ZFOO} command is encountered in program code.
 4130: 
 4131: If you remove a command from this list, you may provide your own private M implementation of the command in the manner described above.
 4132: 
 4133: If an argument is passed to a @code{Z}-command you implement in M, it is made available to your M code in a variable whose name is specified in @code{^$JOB($JOB,"ZCOMMAND_ARGUMENT_NAME")}, which defaults to @code{%}.
 4134: 
 4135: @item @code{PIPE_GLVN} +R +U -D
 4136: Contains an M local or global variable to be used as standard input or standard output for the external shell commands run by @code{!<} and @code{!>}.
 4137: 
 4138: @item @code{ZCOMMAND_ARGUMENT_NAME} +R +U -D
 4139: Returns or sets the variable name in which arguments to user-defined @code{Z}-commands are passed. Defaults to @code{%}.
 4140: 
 4141: @item @code{ZFUNCTIONS} +R +U -D
 4142: Contains a space-delimited list of @code{Z} functions to be treated as intrinsic. Any @code{Z} function not appearing in this list will be treated as a user-defined extrinsic function.
 4143: 
 4144: For instance, if function @code{$ZFOO} does @emph{not} appear in this list, FreeM will attempt to return the value of @code{$$^%ZFOO} called as an extrinsic function.
 4145: 
 4146: If you remove a function from this list, you may provide your own private M implementation of the function in the manner described above.
 4147: 
 4148: @item @code{ZSVS} +R +U -D
 4149: Contains a space-delimited list of @code{Z} special variables to be treated as intrinsic. Any @code{Z} special variable  not appearing in this list will be treated as a user-defined extrinsic function taking no arguments.
 4150: 
 4151: For instance, if the special variable @code{$ZFOO} does @emph{not} appear in this list, FreeM will attempt to return the value of @code{$$^%ZFOO} called as an extrinsic function.
 4152: 
 4153: If you remove a built-in special variable from this list, you may provide your own private M implementation of the special variable in the manner described above.
 4154: 
 4155: @item @code{BREAK_HANDLER} +R +U -D
 4156: Contains M code to be executed when the @code{BREAK} command is run.
 4157: 
 4158: @item @code{ROUTINE_BUFFER_SIZE} +R +U -D
 4159: Returns or sets the number of bytes allocated to each routine buffer. If @code{ROUTINE_BUFFER_AUTO_ADJUST} is set to @code{0}, this determines the maximum size of routines that FreeM will execute.
 4160: 
 4161: @item @code{ROUTINE_BUFFER_COUNT} +R +U -D
 4162: Returns or sets the number of routine buffers that FreeM will store in memory concurrently. Raising this value will increase memory usage, but will also increase performance if your applications call many different routines repeatedly.
 4163: 
 4164: @item @code{ROUTINE_BUFFER_AUTO_ADJUST} +R +U -D
 4165: Determines whether or not the size of routine buffers will be automatically adjusted at runtime. If set to @code{0}, routine buffers will be fixed to the byte size specified in @code{ROUTINE_BUFFER_SIZE} and may be manually resized using @code{ROUTINE_BUFFER_SIZE}. If set to @code{1}, routine buffers will grow automatically as necessary.
 4166: 
 4167: @item @code{SYMBOL_TABLE_SIZE} +R +U -D
 4168: Returns or sets the number of bytes allocated to each of the two FreeM symbol tables. If @code{SYMBOL_TABLE_AUTO_ADJUST} is @code{1}, this value is treated as a default, initial size. If @code{SYMBOL_TABLE_AUTO_ADJUST} is @code{0}, this value controls the fixed size of the two symbol tables.
 4169: 
 4170: @item @code{SYMBOL_TABLE_AUTO_ADJUST} +R +U -D
 4171: Determines whether or not the size of the two FreeM symbol tables will be automatically adjusted at runtime. If set to @code{0}, the symbol table will be fixed to the byte size specified in @code{SYMBOL_TABLE_SIZE} and may be manually resized by modifying @code{SYMBOL_TABLE_SIZE}. If set to @code{1}, the two symbol tables will grow automatically as necessary.
 4172: 
 4173: 
 4174: @item @code{USER_DEFINED_ISV_TABLE_SIZE} +R +U -D
 4175: Returns or sets the number of bytes allocated to the FreeM user-defined intrinsic special variable table. If @code{USER_DEFINED_ISV_TABLE_AUTO_ADJUST} is @code{1}, this value is treated as a default, initial size. If @code{USER_DEFINED_ISV_TABLE_AUTO_ADJUST} is @code{0}, this value controls the fixed byte size of the user-defined intrinsic special variable table.
 4176: 
 4177: @item @code{USER_DEFINED_ISV_TABLE_AUTO_ADJUST} +R +U -D
 4178: Determines whether or not the size of the FreeM user-defined intrinsic special variable table will be automatically adjusted at runtime. If set to @code{0}, the user-defined ISV table will be fixed to the byte size specified in @code{USER_DEFINED_ISV_TABLE_SIZE} and may be manually resized by modifying @code{USER_DEFINED_ISV_TABLE_SIZE}. If set to @code{1}, the user-defined ISV table will grow automatically as necessary.
 4179: 
 4180: @item @code{GVN_UNIQUE_CHARS} +R +U -D
 4181: Returns or sets the number of characters of a global name that make it unique, from 1 to 255.
 4182: 
 4183: @item @code{GVN_CASE_SENSITIVE} +R +U -D
 4184: Returns or sets the case sensitivity of global names. If set to @code{0}, global names are case-insensitive. If set to @code{1}, global names are case-sensitive.
 4185: 
 4186: @item @code{GVN_NAME_SUB_LENGTH} +R +U -D
 4187: Returns or sets the maximum number of characters of a global name plus all of its subscripts, from 1-255.
 4188: 
 4189: @item @code{GVN_SUB_LENGTH} +R +U -D
 4190: Returns or sets the maximum number of characters of a single global subscript, from 1-255.
 4191: 
 4192: @item @code{SINGLE_USER} +R +U -D
 4193: If set to @code{1}, FreeM will skip all file locking operations on globals. If set to @code{0}, FreeM will enforce file locking on both.
 4194: 
 4195: Setting @code{SINGLE_USER} to @code{1} will improve FreeM performance, but you must @emph{ONLY} use this on systems where you are absolutely sure that only one FreeM process will run at any given time, as running multiple instances of FreeM concurrently when any of them are set to @code{SINGLE_USER} mode @emph{will} cause global data corruption.
 4196: 
 4197: @item @code{CHARACTER} +R -U -D
 4198: Returns the character set of the job.
 4199: 
 4200: @item @code{CWD} +R +U -D
 4201: Returns or sets the current working directory of the job.
 4202: 
 4203: @item @code{OPEN} +R -U -D
 4204: The @code{^$JOB($JOB,"OPEN",<channel>} subscripts list the open I/O channels in the specified job.
 4205: 
 4206: @item @code{BERKELEYDB,FLUSH_THRESHOLD} +R +U -D
 4207: Returns or sets the number of write operations that will be cached in the BerkeleyDB global handler prior to flushing BerkeleyDB's cache to disk.
 4208: 
 4209: @item @code{EVENT} +R +U +D
 4210: The subtree contained under @code{^$JOB($J,"EVENT")} defines asynchronous event handlers for the current job. Please see @emph{Asynchronous Event Handling} for more information.
 4211: 
 4212: @item @code{GLOBAL} +R -U -D
 4213: Returns the global environment of the job.
 4214: 
 4215: @item @code{IOPATH} +R +U -D
 4216: Returns or sets the @emph{I/O path} to be used by the @code{OPEN} command.
 4217: 
 4218: @item @code{PRIORITY} +R +U -D
 4219: Returns or sets the @emph{nice} value of the FreeM job.
 4220: 
 4221: @item @code{REVSTR} +R +U -D
 4222: When set to 1, allows @code{$EXTRACT} to accept negative values.
 4223: 
 4224: @item @code{ROUTINE} +R -U -D
 4225: Returns the name of the routine currently being executed by the job.
 4226: 
 4227: @item @code{SYMTAB} +R +U -D
 4228: Returns or sets the current local variable symbol table in use.
 4229: 
 4230: FreeM supports two unique and independent symbol tables, allowing FreeM programs to maintain two independent sets of identically- or differently-named local variables per process.
 4231: 
 4232: The default symbol table is @code{0}, and the alternate symbol table is @code{1}, corresponding to the valid values for @code{^$JOB($JOB,"SYMTAB")}.
 4233: 
 4234: Setting this subscript to values other than @code{0} or @code{1} will result in a @code{ZINVEXPR} error.
 4235: 
 4236: @item @code{$PDISPLAY} +R -U -D
 4237: Returns the value of @code{$PDISPLAY} for the job.
 4238: 
 4239: @item @code{$PRINCIPAL} +R -U -D
 4240: Returns the value of @code{$PRINCIPAL} for the job.
 4241: 
 4242: @item @code{$TLEVEL} +R -U -D
 4243: Returns the current transaction level (value of @code{$TLEVEL} for the job.
 4244: 
 4245: @item @code{$IO} +R -U -D
 4246: Returns the current value of @code{$IO} for the job.
 4247: 
 4248: @item @code{USER} +R -U -D
 4249: Returns the UID of the user owning the job.
 4250: 
 4251: @item @code{GROUP} +R -U -D
 4252: Returns the GID of the group owning the job.
 4253: 
 4254: @item @code{NAMESPACE} +R +U -D
 4255: Returns or sets the name of the job's currently-active namespace.
 4256: 
 4257: @item @code{MATH} +R +U -D
 4258: Returns or sets the mode in which decimal comparisons and arithmetic calculations are conducted. Valid values are @code{FIXED}, for fixed-point decimals having up to 20,000 digits of precision, as determined by the @code{$ZPRECISION} intrinsic special variable, and @code{IEEE754}, to use IEEE 754 floating-point decimals. When in @code{IEEE754} mode, floating-point numbers support up to 16 digits of numeric precision.
 4259: 
 4260: @code{IEEE754} mode will make mathematical calculations significantly faster, especially when accelerated by a floating-point processor, at the expense of precision and accuracy.
 4261: 
 4262: @code{FIXED} mode is recommended for financial calculations, or where precision and accuracy are valued over performance. @code{FIXED} is the default mode of FreeM operation.
 4263: 
 4264: Attempting to @code{SET} this node to values other than @code{FIXED} or @code{IEEE754} will set @code{$ECODE} to @code{M29}.
 4265: 
 4266: @end table
 4267: 
 4268: @node ^$LOCK
 4269: @section ^$LOCK
 4270: @cindex ^$LOCK
 4271: @cindex structured system variables, ^$LOCK
 4272: 
 4273: The first-level subscript of @code{^$LOCK} is a lock name. The value at each node is the PID which owns the lock, a comma, and the lock counter for the locked resource.
 4274: 
 4275: Attempting to @code{SET} or @code{KILL} any node in @code{^$LOCK} will raise error @code{M29}.
 4276: 
 4277: @node ^$OBJECT
 4278: @section ^$OBJECT
 4279: @cindex ^$OBJECT
 4280: @cindex structured system variables, ^$OBJECT
 4281: 
 4282: @node ^$ROUTINE
 4283: @section ^$ROUTINE
 4284: @cindex ^$ROUTINE
 4285: @cindex structured system variables, ^$ROUTINE
 4286: 
 4287: The @code{^$ROUTINE} SSVN exposes a list of routines available in the current FreeM namespace, as well as additional attributes further describing each routine.
 4288: 
 4289: The first-level subscript is the name of a FreeM routine minus the leading caret symbol.
 4290: 
 4291: The following second-level subscripts are supported:
 4292: 
 4293: @table @asis
 4294: 
 4295: @item @code{CHARACTER} +R -U -D
 4296: Returns the character set of the routine.
 4297: 
 4298: @item @code{NAMESPACE} +R -U -D
 4299: Returns the name of the FreeM namespace in which the routine resides.
 4300: 
 4301: @item @code{PATH} +R -U -D
 4302: Returns the full filesystem path to the routine in fixed storage.
 4303: 
 4304: @end table
 4305: 
 4306: @node ^$SYSTEM
 4307: @section ^$SYSTEM
 4308: @cindex ^$SYSTEM
 4309: @cindex structured system variables, ^$SYSTEM
 4310: 
 4311: The @code{^$SYSTEM} SSVN exposes system-level implementation details.
 4312: 
 4313: The following first-level subscripts are supported:
 4314: 
 4315: @table @asis
 4316: 
 4317: @item @code{DEFPSIZE} +R -U -D
 4318: Returns the default size in bytes of the symbol table and routine buffer memory partition.
 4319: 
 4320: @item @code{DEFUDFSVSIZ} +R -U -D
 4321: Returns the default size in bytes of the user-defined intrinsic special variable table.
 4322: 
 4323: @item @code{DEFNSIZE} +R -U -D
 4324: Returns the default size of the @code{NEW} stack, in number of entries.
 4325: 
 4326: @item @code{MAXNO_OF_RBUF} +R -U -D
 4327: Returns the maximum number of routine buffers.
 4328: 
 4329: @item @code{DEFNO_OF_RBUF} +R -U -D
 4330: Returns the default number of routine buffers.
 4331: 
 4332: @item @code{DEFPSIZE0} +R -U -D
 4333: Returns the default size in bytes of each routine buffer.
 4334: 
 4335: @item @code{NO_GLOBLS} +R -U -D
 4336: Returns the maximum number of globals that can be concurrently opened.
 4337: 
 4338: @item @code{NO_OF_GBUF} +R -U -D
 4339: Returns the number of global buffers.
 4340: 
 4341: @item @code{NESTLEVLS} +R -U -D
 4342: Returns the depth of the @code{DO}, @code{FOR}, @code{XECUTE} stack.
 4343: 
 4344: @item @code{PARDEPTH} +R -U -D
 4345: Returns the maximum depth of the parser's parameter stack.
 4346: 
 4347: @item @code{PATDEPTH} +R -U -D
 4348: Returns the maximum number of @emph{patatom}s in each pattern.
 4349: 
 4350: @item @code{TRLIM} +R -U -D
 4351: Returns the trace limit of the @code{BUILTIN} global handler.
 4352: 
 4353: @item @code{ARGS_IN_ESC} +R -U -D
 4354: Returns the maximum number of arguments in a terminal escape sequence.
 4355: 
 4356: @item @code{ZTLEN} +R -U -D
 4357: Returns the maximum length of @code{$ZTRAP}.
 4358: 
 4359: @item @code{FUNLEN} +R -U -D
 4360: Returns the maximum length of the @code{$ZF} (function key) variable.
 4361: 
 4362: @item @code{NAME_LENGTH} +R -U -D
 4363: Returns the maximum length of variable names in the current FreeM build. Compatible with the same SSVN node in @emph{Reference Standard M}
 4364: 
 4365: @item @code{STRING_MAX} +R -U -D
 4366: Returns the maximum length of character strings in the current FreeM build. Compatible with the same SSVN node in @emph{Reference Standard M}
 4367: 
 4368: @item @code{$NEXTOK} +R -U -D
 4369: Returns a value indicating whether or not the @code{$NEXT} intrinsic function is allowed. In FreeM, @code{$NEXT} is always enabled, and this SSVN is provided solely for compatibility with @emph{Reference Standard M}. Thus, this SSVN node always returns @code{1}.
 4370: 
 4371: @item @code{EOK} +R -U -D
 4372: Returns a value indicating whether or not @code{E} notation for exponents is allowed. In FreeM, this feature is always enabled, and this SSVN is provided solely for compatibility with @emph{Reference Standard M}. Thus, this SSVN node always returns @code{1}.
 4373: 
 4374: @item @code{OFFOK} +R -U -D
 4375: Returns a value indicating whether or not offsets are allowed in @code{DO} and @code{GOTO}. In FreeM, this feature is always enabled, and this SSVN is provided solely for compatibility with @emph{Reference Standard M}. Thus, this SSVN node always returns @code{1}.
 4376: 
 4377: @item @code{BIG_ENDIAN} +R -U -D
 4378: Returns a 1 if FreeM is running on a big-endian platform, or a 0 otherwise. Compatible with the same SSVN node in @emph{Reference Standard M}.
 4379: 
 4380: @item @code{NAMESPACE} +R -U -D
 4381: The descendant subscripts of this node list each namespace in the current FreeM environment.
 4382: 
 4383: @item @code{MAPPINGS,GLOBAL} +R -U -D
 4384: Descendant subscripts of this node represent global name mappings set in @code{^$GLOBAL(@emph{gvn},"NAMESPACE")}
 4385: 
 4386: @end table
 4387: 
 4388: @node ^$WINDOW
 4389: @section ^$WINDOW
 4390: @cindex ^$WINDOW
 4391: @cindex structured system variables, ^$WINDOW
 4392: 
 4393: The @code{^$WINDOW} SSVN has no nodes yet defined. However, completing a @code{MERGE} to this SSVN will cause MWAPI-ish things to happen, and further work is proceeding on MWAPI implementation.
 4394: 
 4395: @node ^$ZPROCESS
 4396: @section ^$ZPROCESS
 4397: @cindex ^$ZPROCESS
 4398: @cindex structured system variables, ^$ZPROCESS
 4399: 
 4400: Provides access to @code{procfs}, which is a filesystem-like abstraction for UNIX process metadata contained in @code{/proc}, as well as features for examining and controlling the state of processes external to the FreeM interpreter.
 4401: 
 4402: The first subscript always represents the @emph{process ID} of the external process being acted upon.
 4403: 
 4404: The following values for the second subscript are supported:
 4405: 
 4406: 
 4407: @table @asis
 4408: 
 4409: @item @code{EXISTS} +R -U -D
 4410: Returns 1 if the referenced process exists; 0 otherwise.
 4411: 
 4412: @item @code{ATTRIBUTE} +R -U -D
 4413: Exposes the @code{/proc} files as descendant subscripts, i.e., @code{WRITE ^$ZPROCESS(2900,"ATTRIBUTE","cmdline"),!} would print the initial command line used to invoke process ID 2900. Note that the third subscript (the immediate descendant of the @code{ATTRIBUTE} subscript) is case sensitive.
 4414: 
 4415: @item @code{SIGNAL} -R +U -D
 4416: Allows signals to be sent to the referenced process. The following subscript is an integer value corresponding to the desired signal number. You may obtain a list of signal numbers on most UNIX systems with the command @code{kill -l}.
 4417: 
 4418: The constants @code{%SYS.SIGNAL.HUP}, @code{%SYS.SIGNAL.INT}, @code{%SYS.SIGNAL.KILL}, and @code{%SYS.SIGNAL.TERM} are provided for convenient use of this SSVN subscript.
 4419: 
 4420: @end table
 4421: 
 4422: @node ^$ZRPI
 4423: @section ^$ZRPI
 4424: @cindex ^$ZRPI
 4425: @cindex structured system variables, ^$ZRPI
 4426: 
 4427: The @code{^$ZRPI} structured system variable provides easy access to general-purpose input/output (GPIO) pins on Raspberry Pi single-board computers.
 4428: 
 4429: To initialize the GPIO subsystem, @code{SET ^$ZRPI("INITIALIZE")=1}.
 4430: 
 4431: Individual pins are accessed through @code{^$ZRPI("GPIO",<pin>,...)}, where @code{<pin>} represents the desired pin number. Descendant subscripts of @code{^$ZRPI("GPIO",<pin>)} are as follows:
 4432: 
 4433: @table @asis
 4434: 
 4435: @item @code{MODE} +R +U -D
 4436: Represents the operating mode of the selected pin. One of @code{INPUT}, @code{OUTPUT}, @code{PWM_OUTPUT}, or @code{GPIO_CLOCK}.
 4437: 
 4438: @item @code{DIGITAL} +R +U -D
 4439: Reads or writes the selected pin digitally. The value is limited to @code{1} or @code{0}.
 4440: 
 4441: @item @code{ANALOG} +R +U -D
 4442: Reads or writes the selected pin in an analog fashion. The value represents analog voltage.
 4443: 
 4444: @end table
 4445: 
 4446: @node Operators
 4447: @chapter Operators
 4448: 
 4449: @menu
 4450: * Unary +::                     Force a value to positive.
 4451: * Unary -::                     Force a value to negative.
 4452: * +::                           Add.
 4453: * +=::                          Add and assign.
 4454: * ++::                          Postfix increment.
 4455: * -::                           Subtract.
 4456: * -=::                          Subtract and assign.
 4457: * --::                          Postfix decrement.
 4458: * *::                           Multiply.
 4459: * *=::                          Multiply and assign.
 4460: * /::                           Divide.
 4461: * /=::                          Divide and assign.
 4462: * \::                           Integer divide.
 4463: * \=::                          Integer divide and assign.
 4464: * #::                           Modulo.
 4465: * #=::                          Modulo and assign.
 4466: * **::                          Exponentiate.
 4467: * **=::                         Exponentiate and assign.
 4468: * <::                           Less than.
 4469: * <=::                          Less than or equal to.
 4470: * >::                           Greater than.
 4471: * >=::                          Greater than or equal to.
 4472: * _::                           Concatenate.
 4473: * _=::                          Concatenate and assign.
 4474: * =::                           Equals.
 4475: * [::                           Contains.
 4476: * ]::                           Follows.
 4477: * ]]::                          Sorts after.
 4478: * ?::                           Pattern match.
 4479: * &::                           Logical AND.
 4480: * ! (Operator)::                Logical OR.
 4481: * '::                           Logical NOT.
 4482: * @@ (Operator)::               Indirect
 4483: @end menu
 4484: 
 4485: @node Unary +
 4486: @section Unary +
 4487: @cindex operators, unary +
 4488: 
 4489: Forces a number to positive, whether positive or negative. Also forces numeric coercion of strings.
 4490: 
 4491: @node Unary -
 4492: @section Unary -
 4493: @cindex operators, unary -
 4494: 
 4495: Forces a number to negative, whether positive or negative. Also forces numeric coercion of strings.
 4496: 
 4497: @node +
 4498: @section + (Add)
 4499: @cindex operators, +
 4500: 
 4501: @emph{Syntax}
 4502: 
 4503: @example
 4504: S X=1+2 ; => 3
 4505: @end example
 4506: 
 4507: Adds numbers together.
 4508: 
 4509: @node +=
 4510: @section += (Add/Assign)
 4511: @cindex operators, +=
 4512: 
 4513: @emph{Syntax}
 4514: 
 4515: @example
 4516: S X=5
 4517: S X+=3 ; => 8
 4518: @end example
 4519: 
 4520: Increments the variable on the LHS by the value on the RHS.
 4521: 
 4522: @node ++
 4523: @section ++ (Postfix Increment)
 4524: @cindex operators, ++
 4525: 
 4526: Increments a variable by 1.
 4527: 
 4528: @node -
 4529: @section - (Subtract)
 4530: @cindex operators, -
 4531: 
 4532: Subtracts one number from another.
 4533: 
 4534: @node -=
 4535: @section -= (Subtract/Assign)
 4536: @cindex operators, -=
 4537: 
 4538: @emph{Syntax}
 4539: 
 4540: @example
 4541: S X=5
 4542: S X-=3 ; => 2
 4543: @end example
 4544: 
 4545: Decrements the variable on the LHS by the value on the RHS.
 4546: 
 4547: @node --
 4548: @section -- (Postfix Decrement)
 4549: @cindex operators, --
 4550: 
 4551: Decrements the variable by one.
 4552: 
 4553: @node *
 4554: @section * (Multiply)
 4555: @cindex operators, *
 4556: 
 4557: Multiplies one number by another.
 4558: 
 4559: @node *=
 4560: @section *= (Multiply/Assign)
 4561: @cindex operators, *=
 4562: 
 4563: 
 4564: 
 4565: @node /
 4566: @section / (Divide)
 4567: @cindex operators, /
 4568: 
 4569: @node /=
 4570: @section /= (Divide/Assign)
 4571: @cindex operators, /=
 4572: 
 4573: @node \
 4574: @section \ (Integer Divide)
 4575: @cindex operators, \
 4576: 
 4577: @node \=
 4578: @section \= (Integer Divide/Assign)
 4579: @cindex operators, \=
 4580: 
 4581: @node #
 4582: @section # (Modulo)
 4583: @cindex operators, #
 4584: 
 4585: @node #=
 4586: @section #= (Modulo/Assign)
 4587: @cindex operators, #=
 4588: 
 4589: @node **
 4590: @section ** (Exponentiate)
 4591: @cindex operators, **
 4592: 
 4593: @node **=
 4594: @section **= (Exponentiate/Assign)
 4595: @cindex operators, **=
 4596: 
 4597: @node <
 4598: @section < (Less Than)
 4599: @cindex operators, <
 4600: 
 4601: @node <=
 4602: @section <= (Less Than or Equal To)
 4603: @cindex operators, <=
 4604: 
 4605: @node >
 4606: @section > (Greater Than)
 4607: @cindex operators, >
 4608: 
 4609: @node >=
 4610: @section >= (Greater Than or Equal To)
 4611: @cindex operators, >=
 4612: 
 4613: @node _
 4614: @section _ (Concatenate)
 4615: @cindex operators, _
 4616: 
 4617: @node _=
 4618: @section _= (Concatenate/Assign)
 4619: @cindex operators, _=
 4620: 
 4621: @node =
 4622: @section = (Equals)
 4623: @cindex operators, =
 4624: 
 4625: @node [
 4626: @section [ (Contains)
 4627: @cindex operators, [
 4628: 
 4629: @node ]
 4630: @section ] (Follows)
 4631: @cindex operators, ]
 4632: 
 4633: @node ]]
 4634: @section ]] (Sorts After)
 4635: @cindex operators, ]]
 4636: 
 4637: @node ?
 4638: @section ? (Pattern Match)
 4639: @cindex operators, ?
 4640: 
 4641: @node &
 4642: @section & (Logical AND)
 4643: @cindex operators, &
 4644: 
 4645: @node ! (Operator)
 4646: @section ! (Logical OR)
 4647: @cindex operators, !
 4648: 
 4649: @node '
 4650: @section ' (Logical NOT)
 4651: @cindex operators, '
 4652: 
 4653: @node @@ (Operator)
 4654: @section @@ (Indirect)
 4655: @cindex operators, @@
 4656: 
 4657: @node Routines
 4658: @chapter Routines
 4659: @cindex routines
 4660: 
 4661: A @emph{routine} is a file containing M source code to be processed by FreeM.
 4662: 
 4663: Routines exist within a @emph{namespace} (such as @code{SYSTEM} or @code{USER}), which in turn exist within an @emph{environment} (such as @code{DEFAULT}).
 4664: 
 4665: @menu
 4666: * Routine Naming::              Requirements and conventions for routine names.
 4667: @end menu
 4668: 
 4669: 
 4670: @node Routine Naming
 4671: @section Routine Naming
 4672: The routine's filename follows the format @code{NAME.m}, where @code{NAME} is the name of the routine, and @code{.m} is the filename extension.
 4673: 
 4674: Routine naming rules are as follows:
 4675: 
 4676: @itemize @bullet
 4677: @item Routine names must begin with an upper- or lower-case letter, or a @code{%} sign
 4678: @item Within the routine name, you may have upper-case or lower-case letters or digits
 4679: @item The entire routine name must not be longer than 255 characters
 4680: @end itemize
 4681: 
 4682: Routines whose names begin with @code{%} must be located in the @code{SYSTEM} namespace. Other routines may be located in any namespace.
 4683: 
 4684: @node Types
 4685: @chapter Types
 4686: @cindex types
 4687: @cindex data types
 4688: 
 4689: FreeM supports all @emph{libdatatype} types defined in the former MDC's @emph{Millennium Draft Standard}, with the exception of @code{MATRIX}, and with extensions supporting object-oriented programming. A notable enhancement in FreeM is that the library data types can be used in the @emph{formallist} of any extrinsic function or subroutine; not only in @emph{libraryelement}s.
 4690: 
 4691: @menu
 4692: * BOOLEAN::                     Truth values.
 4693: * COMPLEX::                     Numbers with real and imaginary parts.
 4694: * INTEGER::                     Numbers with no decimal part.
 4695: * REAL::                        Numbers with a decimal part.
 4696: * STRING::                      Arbitrary strings of characters.
 4697: * Custom Types (Classes)::      User-defined, object-oriented types.
 4698: @end menu
 4699: 
 4700: @node BOOLEAN
 4701: @section BOOLEAN
 4702: @cindex data types, BOOLEAN
 4703: @cindex types, BOOLEAN
 4704: 
 4705: The @code{BOOLEAN} type represents any M value that can be interpreted as a truth-value.
 4706: 
 4707: @node COMPLEX
 4708: @section COMPLEX
 4709: @cindex data types, COMPLEX
 4710: @cindex types, COMPLEX
 4711: 
 4712: The @code{COMPLEX} type is a complex number represented as a string in the format @code{@emph{<real-part>}%@emph{<imaginary-part>}}, where @emph{real-part} and @emph{imaginary-part} are both @code{REAL} numbers. See @ref{REAL} for more information.
 4713: 
 4714: FreeM will attempt to interpret any @code{COMPLEX} value according to the usual rules for M canonical numbers, i.e., the string @code{sabc123.345%fbd3.1} would be interpreted as a complex number with the real part being @code{123.345} and the imaginary part being @code{3.1}.
 4715: 
 4716: @node INTEGER
 4717: @section INTEGER
 4718: @cindex data types, INTEGER
 4719: @cindex types, INTEGER
 4720: 
 4721: An @code{INTEGER} is an interpretation of numeric data with any fractional part removed.
 4722: 
 4723: @node REAL
 4724: @section REAL
 4725: @cindex data types, REAL
 4726: @cindex types, REAL
 4727: 
 4728: A @code{REAL} is a numeric interpretation of data including a fractional part.
 4729: 
 4730: @node STRING
 4731: @section STRING
 4732: @cindex data types, STRING
 4733: @cindex types, STRING
 4734: 
 4735: The @code{STRING} is the fundamental FreeM data type. Other types are inferred from the context of their usage.
 4736: 
 4737: @subsection String Rules
 4738: 
 4739: The following rules apply to all FreeM strings:
 4740: 
 4741: @itemize
 4742: @item Must not exceed 255 characters
 4743: @item Must not contain @code{$C(0)}, @code{$C(201)}, or @code{$C(202)}
 4744: @end itemize
 4745: 
 4746: @subsection String Quoting Rules
 4747: Strings in FreeM must be surrounded in double quotes:
 4748: 
 4749: @example
 4750: SET MYSTRING="This is a string literal"
 4751: @end example
 4752: 
 4753: If you want to include double quotes inside of a string, simply double them:
 4754: 
 4755: @example
 4756: SET MYSTRING="This is a ""string literal"" with embedded double quotes"
 4757: @end example
 4758: 
 4759: 
 4760: @node Custom Types (Classes)
 4761: @section Custom Types (Classes)
 4762: @cindex data types, custom
 4763: @cindex types, custom
 4764: @cindex classes
 4765: 
 4766: See @ref{Object-Oriented Programming}.
 4767: 
 4768: @node Globals
 4769: @chapter Globals
 4770: @cindex globals
 4771: @cindex variables, global
 4772: @cindex data
 4773: 
 4774: @menu
 4775: * Globals Overview::            Basics of FreeM persistent storage.
 4776: * Creating Globals::            How to create globals.
 4777: * Removing Globals::            How to remove globals.
 4778: * Global Storage::              How globals are stored.
 4779: @end menu
 4780: 
 4781: @node Globals Overview
 4782: @section Globals Overview
 4783: 
 4784: FreeM supports typical M globals, which are often described as persistent, hierachical sparse arrays. Globals make it relatively simple to include persistent data in an application without requiring the developer to use an external database management system, and offer syntax and semantics so similar to M local variables and structured system variables that moving from one to the other is seamless.
 4785: 
 4786: Each global comprises three elements:
 4787: 
 4788: @itemize @bullet
 4789: @item
 4790: An alphabetic name beginning with a caret (@code{^}) or a caret and a percent sign (@code{^%})
 4791: @item
 4792: Optionally, one or more comma-delimited subscripts, enclosed in parentheses
 4793: @item
 4794: A value of up to 255 characters in length
 4795: @end itemize
 4796: 
 4797: A leading percent sign in the global name will force the named global into the @code{SYSTEM} namespace of the current FreeM environment.
 4798: 
 4799: @node Creating Globals
 4800: @section Creating Globals
 4801: @cindex globals, creating
 4802: 
 4803: To create a global, you can use the @code{SET} command:
 4804: 
 4805: @example
 4806: SET ^MYGLOBAL("foo","bar")="this is the data value"
 4807: @end example
 4808: 
 4809: @node Removing Globals
 4810: @section Removing Globals
 4811: @cindex globals, removing
 4812: 
 4813: To remove an entire global, you can use the @code{KILL} command with the unsubscripted name of the global:
 4814: 
 4815: @example
 4816: KILL ^MYGLOBAL
 4817: @end example
 4818: 
 4819: If you only want to remove part of a global, i.e., beginning at a certain subscript level, use the @code{KILL} command with a subscripted name:
 4820: 
 4821: @example
 4822: KILL ^MYGLOBAL("foo")
 4823: @end example
 4824: 
 4825: This will remove only the @code{"foo"} subscript and all of its children.
 4826: 
 4827: If you only want to remove the data value at a specific subscript level, leaving the subscript itself intact, use @code{KVALUE}:
 4828: 
 4829: @example
 4830: KVALUE ^MYGLOBAL("foo")
 4831: @end example
 4832: 
 4833: @node Global Storage
 4834: @section Global Storage
 4835: @cindex globals, storage
 4836: 
 4837: FreeM globals are stored in @code{$PREFIX/var/freem/@emph{<environment-name>}/@emph{<namespace-name>}/globals} in a binary format.
 4838: 
 4839: Global files have a header of the following format:
 4840: 
 4841: @verbatim
 4842: typedef struct global_header {
 4843:     
 4844:     char magic[5]; /* FRMGL */
 4845:     int format_version;
 4846:     char host_triplet[40];
 4847:     char host_id[256];
 4848:     
 4849:     unsigned long block_size;
 4850:     unsigned long last_transaction_id;
 4851: 
 4852:     long created;
 4853:     long last_backup;
 4854:     
 4855: } global_header;
 4856: @end verbatim
 4857: 
 4858: @node Concurrency Control
 4859: @chapter Concurrency Control
 4860: @cindex concurrency control
 4861: @cindex locking
 4862: @cindex transaction processing
 4863: 
 4864: @menu
 4865: * Concurrency Control Overview::                Basics of concurrency control.
 4866: * Advisory Locks::                              Coordinating access voluntarily.
 4867: * Transaction Processing::                      Ensuring logical consistency.
 4868: @end menu
 4869: 
 4870: @node Concurrency Control Overview
 4871: @section Concurrency Control Overview
 4872: 
 4873: Multitasking, multi-user FreeM applications must concern themselves with conscientious management of concurrent access to globals in order to maintain logical consistency and prevent concurrent reads and writes from conflicting with each other.
 4874: 
 4875: In FreeM, there are two mechanisms provided for managing concurrent global access: @emph{advisory locks}, and @emph{transaction processing}.
 4876: 
 4877: Advisory locks allow applications to voluntarily coordinate concurrent access to globals with the @code{LOCK} command, and require each application to check the @code{LOCK} status prior to accessing a global.
 4878: 
 4879: Transaction processing allows applications to delineate sets of global operations (sets, kills, etc.) as being part of a transaction, in which no operations are performed against the globals contained within the transaction until the transaction is committed. In addition, processes other than the one running the transaction will be forced to wait to access globals for either the duration of the commit phase (@emph{batch mode}), or for the entire duration of the transaction (@emph{serial mode}).
 4880: 
 4881: @node Advisory Locks
 4882: @section Advisory Locks
 4883: 
 4884: @node Transaction Processing
 4885: @section Transaction Processing
 4886: @cindex transaction processing
 4887: 
 4888: FreeM implements a significant subset of the transaction processing features from @emph{ANSI X11.1-1995}. This allows a series of global operations to be conducted all at once, either in batch mode (where concurrent operation is not interrupted until the last possible moment), or in serial mode (where writes are guaranteed to be atomic, consistent, isolated, and durable).
 4889: 
 4890: @subsection Theory of Operation
 4891: 
 4892: FreeM uses a pessimistic concurrency control mechanism for @code{SERIAL} transactions, meaning that any @code{TSTART} command that includes the @code{SERIAL} transaction parameter will cause the process to acquire the transaction processing mutex, which prevents any process but the one holding the mutex from performing any data access (read or write) until either @code{TCOMMIT} or @code{TROLLBACK} is called, either committing or rolling back the transaction, respectively.
 4893: 
 4894: Any transaction in between its @code{TSTART} and @code{TCOMMIT}/@code{TROLLBACK} is said to be @emph{in-flight}. During the in-flight stage, pending global operations are held only in memory and after-image journals.
 4895: 
 4896: FreeM maintains a list of all globals affected during a transaction in-flight. When a @code{TCOMMIT} is reached, FreeM will generate a @emph{checkpoint} of each global data file to be changed by the transaction. These checkpoints allow all FreeM globals to be restored to their pre-transaction state if a @code{TCOMMIT} should fail part of the way through its operation. 
 4897: 
 4898: Checkpoints can have one of two modes:
 4899: 
 4900: @table @asis
 4901: 
 4902: @item @code{CP_REMOVE}
 4903: Used for globals that did not exist prior to the beginning of this transaction. Simply marks the entire global data file for deletion in case of @code{TCOMMIT} failure.
 4904: 
 4905: @item @code{CP_RESTORE}
 4906: Used for globals that @emph{did} exist prior to the beginning of this transaction. In this case, the entire global data file is copied to a new file with a @code{.chk} extension. In cases of @code{TCOMMIT} failure, @code{CP_RESTORE} checkpoint files will be restored over the partially-modified live data file.
 4907: 
 4908: @end table
 4909: 
 4910: The below example shows a few global operations and checkpoints for a transaction in-flight using the @code{trantab} direct-mode command:
 4911: 
 4912: @verbatim
 4913: TL1:DEFAULT.USER> trantab
 4914:  $TLEVEL 1*
 4915:   Operations for Transaction ID: 6ea14aad-b8f1-47f9-9f52-4f513f892bc0 [RESTARTABLE SERIAL]
 4916: 
 4917:    OP. NO.   ACTION         KEY/DATA
 4918:    -------   ------         --------
 4919:    1         SET            ^FOO=3
 4920:    2         KILL           ^FOO
 4921:    3         SET            ^snw=10
 4922:    4         SET            ^BRANDNEW=6
 4923: 
 4924:   Global checkpoints:
 4925: 
 4926:    GLOBAL                        MODE                FILES
 4927:    ------                        ----                -----
 4928:    ^BRANDNEW                     CP_REMOVE           IN:   /usr/local/var/freem/USER/globals/^BRANDNEW
 4929:    ^snw                          CP_RESTORE          IN:   /usr/local/var/freem/USER/globals/^snw
 4930:                                                      OUT:  /usr/local/var/freem/USER/globals/^snw.23390.1.chk
 4931:    ^FOO                          CP_RESTORE          IN:   /usr/local/var/freem/USER/globals/^FOO
 4932:                                                      OUT:  /usr/local/var/freem/USER/globals/^FOO.23390.1.chk
 4933: @end verbatim
 4934: 
 4935: In the above example, @code{IN} files are the live data file that will be overwritten or removed, and @code{OUT} files are the checkpoints themselves. Note that @code{OUT} files are only used for @code{CP_RESTORE} checkpoints.
 4936: 
 4937: @subsection Using Transaction Processing
 4938: 
 4939: To use transactions in FreeM, you need to be familiar with three commands:
 4940: 
 4941: @itemize @bullet
 4942: @item
 4943: @code{TSTART}
 4944: @item
 4945: @code{TCOMMIT}
 4946: @item
 4947: @code{TROLLBACK}
 4948: @end itemize
 4949: 
 4950: With transaction processing, global variable operations occurring between @code{TSTART} and @code{TCOMMIT} commands will be contained within the transaction.
 4951: 
 4952: The atomicity, consistency, isolation, and durability facets of FreeM transaction hinge on the transaction mode.
 4953: 
 4954: @subsubsection BATCH Transactions
 4955: @code{BATCH} transactions offer higher performance, and allow other applications aside from the one doing the transaction to continue normal operations until the transaction is committed with @code{TCOMMIT}. In batch mode, other processes are only locked out of normal operation during the commit phase of the transaction.
 4956: 
 4957: The effect of this is that the operations within the batch transaction will not be interleaved with global writes from other applications, but the entire lifetime of the transaction is not guaranteed to be serialized with respect to the transaction processing activities of other running applications in the environment.
 4958: 
 4959: @subsubsection SERIAL Transactions
 4960: @code{SERIAL} transactions offer full ACID compliance at the expense of multiprocessing performance. In serial mode, a @code{TSTART} blocks all activity from all other FreeM processes in the environment, and this blocking effect is not released until the transaction is committed with @code{TCOMMIT} or rolled back with @code{TROLLBACK} (or due to abnormal conditions in the environment that preclude the successful completion of the transaction).
 4961: 
 4962: @node Local Variables
 4963: @chapter Local Variables
 4964: @cindex variables, local
 4965: @cindex local variables
 4966: 
 4967: @menu
 4968: * Local Variables Overview::            The basics of locals.
 4969: * Creating Local Variables::            Creating locals with SET.
 4970: * Removing Local Variables::            Removing locals with KILL.
 4971: @end menu
 4972: 
 4973: @node Local Variables Overview
 4974: @section Local Variables Overview
 4975: 
 4976: FreeM @emph{local variables} have the same data structure as global variables, but are scoped to a single FreeM process, and stored in memory.
 4977: 
 4978: Each local comprises three elements:
 4979: 
 4980: @itemize @bullet
 4981: @item
 4982: An alphabetic name beginning with a letter or a percent sign (@code{%})
 4983: @item
 4984: Optionally, one or more comma-delimited subscripts, enclosed in parentheses
 4985: @item
 4986: A value of up to 255 characters in length
 4987: @end itemize
 4988: 
 4989: @node Creating Local Variables
 4990: @section Creating Local Variables
 4991: @cindex local variables, creating
 4992: 
 4993: To create a local variable, use the @code{SET} command:
 4994: 
 4995: @example
 4996: SET MYLOCAL("foo","bar")="this is the data value"
 4997: @end example
 4998: 
 4999: @node Removing Local Variables
 5000: @section Removing Local Variables
 5001: @cindex local variables, removing
 5002: 
 5003: To remove an entire local variable, you can use the @code{KILL} command with the unsubscripted name of the variable:
 5004: 
 5005: @example
 5006: KILL MYLOCAL
 5007: @end example
 5008: 
 5009: If you only want to remove part of a local variable, i.e., beginning at a certain subscript level, use the @code{KILL} command with a subscripted name:
 5010: 
 5011: @example
 5012: KILL MYLOCAL("foo")
 5013: @end example
 5014: 
 5015: This will remove only the @code{"foo"} subscript and all of its children.
 5016: 
 5017: If you only want to remove the data value at a specific subscript level, leaving the subscript itself intact, use @code{KVALUE}:
 5018: 
 5019: @example
 5020: KVALUE MYLOCAL("foo")
 5021: @end example
 5022: 
 5023: @node Scoping
 5024: @chapter Scoping
 5025: @cindex scoping
 5026: 
 5027: 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.
 5028: 
 5029: M provides the @code{NEW} command to work around these issues. When @code{NEW} is called with a local variable as its argument, FreeM will scope the variable to the process stack frame in which the @code{NEW} command occured. When exiting the stack frame (i.e. with the @code{QUIT} command), FreeM will restore the variable to its value prior to being @code{NEW}ed.
 5030: 
 5031: @emph{Example}
 5032: 
 5033: @example
 5034: MYRTN ;
 5035:   S J=1 ; set local variable J to 1
 5036:   W J,! ; this will output "1"
 5037:   D X   ; execute subroutine X
 5038:   W J,! ; this will output "1", as the value of J was restored
 5039:   Q
 5040:   ;;
 5041: X ;
 5042:   N J   ; stack J
 5043:   S J=6 ; set its value to 6
 5044:   W J,! ; this will output "6"
 5045:   Q     ; quit from the subroutine, destroying its stack frame
 5046:   ;;
 5047: @end example
 5048: 
 5049: @section Scoping Considerations for $TEST
 5050: 
 5051: In M, the truth value of comparisons, logic operations, and certain forms of @code{LOCK} is stored in the @code{$TEST} intrinsic special variable, which follows the same rules as any M local variable.
 5052: 
 5053: This is probably the most significant design flaw of the language, as the side effects of logic on @code{$TEST} lead to incredibly difficult bugs. However, M allows @code{$TEST} to be @code{NEW}ed, and FreeM provides the @code{THEN} command@footnote{From MDC Type A extension X11/1998-31} to help in the case of conditionals. @code{THEN} stacks @code{$TEST} to the end of the line.
 5054: 
 5055: When writing new M code in FreeM, we strongly suggest using @code{THEN} as follows:
 5056: 
 5057: @example
 5058: MYRTN ;
 5059:   IF MYVAR=1 THEN DO SUBRT
 5060: @end example
 5061: 
 5062: This is instead of the traditional form:
 5063: 
 5064: @example
 5065: MYRTN ;
 5066:   IF MYVAR=1 DO SUBR
 5067: @end example
 5068: 
 5069: @cartouche
 5070: @quotation
 5071: @emph{Style Recommendation}
 5072: 
 5073: Note that @code{THEN} is not in any currently published version of the @emph{Standard}, but is part of MDC Type A extension X11/1998-31. However, we recommend using @code{THEN} instead of favoring portability, as there is no defensible reason for this incredibly simple feature @emph{not} to be ubiquitous.
 5074: 
 5075: If you use other M implementations, you should bug the implementers to implement @code{THEN}, as it at least partially mitigates an inexcusable flaw in the design of M.
 5076: @end quotation
 5077: @end cartouche
 5078: 
 5079: @node Decision Constructs
 5080: @chapter Decision Constructs
 5081: @cindex decision constructs
 5082: @cindex IF
 5083: @cindex ELSE
 5084: @cindex THEN
 5085: @cindex postconditionals
 5086: 
 5087: @node Branch Constructs
 5088: @chapter Branch Constructs
 5089: @cindex branch constructs
 5090: @cindex DO
 5091: @cindex GOTO
 5092: @cindex JOB
 5093: 
 5094: @node Loop Constructs
 5095: @chapter Loop Constructs
 5096: @cindex loop constructs
 5097: @cindex FOR
 5098: 
 5099: @node Modular Programming
 5100: @chapter Modular Programming
 5101: @cindex modular programming
 5102: @cindex functions, extrinsic
 5103: @cindex subroutines
 5104: 
 5105: @menu
 5106: * Subroutines::         Making sections of code reusable.
 5107: * Extrinsic Functions:: Reusable code that returns a value.
 5108: @end menu
 5109: 
 5110: @node Subroutines
 5111: @section Subroutines
 5112: 
 5113: @node Extrinsic Functions
 5114: @section Extrinsic Functions
 5115: 
 5116: @node Object-Oriented Programming
 5117: @chapter Object-Oriented Programming
 5118: @cindex object-oriented programming
 5119: @cindex programming, object-oriented
 5120: 
 5121: @menu
 5122: * Classes::                             The organizing concept of object-oriented programming.
 5123: * Inheritance::                         Making one class derive from another.
 5124: * Methods::                             Attach code to classes.
 5125: * Public and Private Variables::        Determining accessibility.
 5126: * Instantiating Objects::               Creating instances of classes.
 5127: @end menu
 5128: 
 5129: @node Classes
 5130: @section Classes
 5131: @subsection Class Overview
 5132: 
 5133: A @emph{class} is the primary organizing concept of FreeM support for object-oriented programming, and in FreeM, is simply an M routine with a few special properties:
 5134: 
 5135: @example
 5136: MYCLASS(THIS,INIT):OBJECT ; Constructor for MYCLASS, inherits OBJECT
 5137:   ; two private variables
 5138:   S THIS("NUMERATOR"):PRIVATE=$P(INIT,"/",1)
 5139:   S THIS("DENOMINATOR"):PRIVATE=$P(INIT,"/",2)
 5140:   Q
 5141:   ;
 5142: DESTROY(THIS) ; This is the destructor
 5143:   Q
 5144: @end example
 5145: 
 5146: The above example demonstrates general class syntax.
 5147: 
 5148: @subsection Constructors
 5149: 
 5150: A @emph{constructor} is an M entry point that is called when a new instance of a class is created.
 5151: 
 5152: A constructor must be the first entry point in a class routine, its tag must match the class/routine name, and it must take two arguments, @code{THIS} and @code{INIT}.
 5153: 
 5154: @code{THIS} represents the instance of the object being accessed, and @code{INIT} represents an initializer that can be used to assign an initial value to the object when instantiating the class.
 5155: 
 5156: A constructor looks like this:
 5157: 
 5158: @example
 5159: %FRACTION(THIS,INIT):OBJECT ;
 5160:    S THIS("NUMERATOR"):PRIVATE=$P(INIT,"/",1)
 5161:    S THIS("DENOMINATOR"):PRIVATE=$P(INIT,"/",2)
 5162:    Q
 5163: @end example
 5164: 
 5165: @emph{Syntax}
 5166: @example
 5167: @emph{<class-name>}(THIS,INIT)[:@emph{<superclass>}]
 5168: @end example
 5169: 
 5170: In the above example, @emph{<superclass>} represents the name of a class from which this class should inherit. In this case, the @code{FRACTION} class inherits from the @code{OBJECT} class. Note that this is not strictly necessary in this case, as all classes in FreeM automatically inherit from @code{OBJECT}.
 5171: 
 5172: @subsection Destructors
 5173: A @code{destructor} is called when you @code{KILL} an instance variable. Its tag must be @code{DESTROY}, and it must take one argument (@code{THIS}).
 5174: 
 5175: The destructor should be used to clean up any resources used by class methods.
 5176: 
 5177: A destructor looks like this:
 5178: 
 5179: @example
 5180: DESTROY(THIS) ;
 5181:   ; free any resources that should be freed at the end of the object's lifetime
 5182:   Q
 5183: @end example
 5184: 
 5185: @node Inheritance
 5186: @section Inheritance
 5187: 
 5188: Every class you create will automatically inherit the methods and functionality of the @code{OBJECT} class, supplied with FreeM.
 5189: 
 5190: When attempting to call a method, FreeM will first search the class routine for a matching entry point, and then follow the inheritance chain upwards until a matching entry point is found. If the final class in the chain does not have a matching entry point, FreeM will try to find a matching entry point in the @code{OBJECT} class.
 5191: 
 5192: Inheritance is achieved by specifying the name of the superclass in the constructor:
 5193: 
 5194: @example
 5195: CLASS(THIS,INIT):SUPERCLASS
 5196: @end example
 5197: 
 5198: @subsection Runtime Polymorphism
 5199: 
 5200: You can achieve runtime polymorphism by subclassing, and defining methods in the subclass that match the names of existing methods in the superclass. Following FreeM inheritance rules, the overridden method in the subclass will be called, and the method in the superclass will not.
 5201: 
 5202: Note that the overridden method in the subclass can take a different set or number of arguments than the @emph{formallist} of the superclass method would specify.
 5203: 
 5204: @node Methods
 5205: @section Methods
 5206: Class methods are defined as tags with @emph{formallist}s in a class routine, and per the typical FreeM object pattern, must take at least one argument, being @code{THIS} (representing a reference to the object instance being accessed).
 5207: 
 5208: The following class (@code{MYCLASS}) has a constructor, a destructor, and a method called @code{MYMETHOD}:
 5209: 
 5210: @example
 5211: %MYCLASS(THIS,INIT) ;
 5212:   Q THIS
 5213: DESTROY(THIS) ;
 5214:   Q
 5215: MYMETHOD(THIS) ;
 5216:   Q "VALUE"
 5217: @end example
 5218: 
 5219: The dot operator is used to invoke class methods:
 5220: 
 5221: @example
 5222: DEFAULT.USER> N MYOBJ=$#^%MYCLASS("")
 5223: DEFAULT.USER> W MYOBJ.MYMETHOD()
 5224: VALUE
 5225: @end example
 5226: 
 5227: @node Public and Private Variables
 5228: @section Public and Private Variables
 5229: 
 5230: FreeM supports private fields with the @code{:PRIVATE} specifier in the @code{SET} command, enforcing classical object-oriented data encapsulation. The @code{:PUBLIC} specifier is provided for completeness, and is the default.
 5231: 
 5232: The below constructor for a @code{FRACTION} class defines two private fields:
 5233: 
 5234: @example
 5235: %FRACTION(THIS,INIT):OBJECT ;
 5236:    S THIS("NUMERATOR"):PRIVATE=$P(INIT,"/",1)
 5237:    S THIS("DENOMINATOR"):PRIVATE=$P(INIT,"/",2)
 5238:    Q
 5239: @end example   
 5240: 
 5241: Either of the following commands will create a public field:
 5242: 
 5243: @example
 5244:   S THIS("VARNAM")="Initial Value"
 5245:   S THIS("VARNAM"):PUBLIC="Initial Value"
 5246: @end example
 5247: 
 5248: Attempting to access private fields from outside of the class will raise error condition @code{ZOBJFLDACCV}. 
 5249: 
 5250: @node Instantiating Objects
 5251: @section Instantiating Objects
 5252: 
 5253: To instantiate an object (i.e., create an object from a certain class), you will use the @code{NEW} command as follows:
 5254: 
 5255: @example
 5256: NEW MYSTR=$#^%STRING("myString")
 5257: @end example
 5258: 
 5259: This will create a local variable called MYSTR of type STRING, and initialize it with the value myString. 
 5260: 
 5261: @subsection Determining Object Class
 5262: 
 5263: To determine the class of any FreeM local variable, you will use the @code{$$TYPE()} method:
 5264: 
 5265: @example
 5266: USER> W MYSTR.$$TYPE()
 5267: ^%STRING
 5268: @end example
 5269: 
 5270: The @code{$$TYPE()} method is a member of the @code{OBJECT} class. 
 5271: 
 5272: @node Libraries
 5273: @chapter Libraries
 5274: @cindex libraries
 5275: 
 5276: @node Sequential I/O
 5277: @chapter Sequential I/O
 5278: 
 5279: @node Network I/O
 5280: @chapter Network I/O
 5281: @cindex networks, input and output
 5282: 
 5283: Network I/O in FreeM is supplied through I/O channels 100-255. The normal @code{READ} and @code{WRITE} syntax will work with network sockets, with a few exceptions.
 5284: 
 5285: @section Opening and Connecting a Client Socket
 5286: @cindex networks, opening and connecting client sockets
 5287: 
 5288: To open a client socket and connect to it, you will need to call the @code{OPEN} command and the @code{USE} command:
 5289: 
 5290: @example
 5291:   ;
 5292:   ; Set socket read terminator to LF
 5293:   ;
 5294:   SET ^$DEVICE(100,"OPTIONS","TERMINATOR")=$C(10)
 5295:   ;
 5296:   ; Open an IPv4 TCP socket to mail.mydomain.com on port 25 (SMTP)
 5297:   ; and connect to it
 5298:   ;
 5299:   OPEN 100:"mail.mydomain.com:25:IPV4:TCP"
 5300:   USE 100:/CONNECT
 5301:   ;
 5302:   ; Read a line of input from the remote host and write it to the terminal
 5303:   ;
 5304:   NEW LINE
 5305:   READ LINE
 5306:   USE 0
 5307:   WRITE LINE,!
 5308:   ;
 5309:   ; CLOSE the socket and disconnect
 5310:   ;
 5311:   CLOSE 100
 5312:   QUIT
 5313: @end example
 5314: 
 5315: @node Extended Global References
 5316: @chapter Extended Global References
 5317: @cindex global references, extended
 5318: @cindex extended global references
 5319: 
 5320: @section Standard Extended Global References
 5321: @cindex extended global references, standard
 5322: 
 5323: FreeM supports extended global references, allowing the user to access globals in namespaces other than the current default namespace and the @code{SYSTEM} namespace, without switching to the other namespace.
 5324: 
 5325: For example, if you are in the @code{USER} namespace, the following code will print the value of @code{^VA(200,0)} in the @code{VISTA} namespace:
 5326: 
 5327: @example
 5328:   WRITE ^|"VISTA"|VA(200,0),!
 5329: @end example
 5330: 
 5331: You may also use an expression that resolves to a string containing a valid namespace name:
 5332: 
 5333: @example
 5334:   SET NS="VISTA"
 5335:   WRITE ^|NS|VA(200,0),!
 5336: @end example  
 5337: 
 5338: @node Global Aliasing
 5339: @chapter Global Aliasing
 5340: @cindex aliasing, global
 5341: @cindex globals, aliasing
 5342: 
 5343: FreeM provides the ability to set alternative names for M global variables.
 5344: 
 5345: To create an alias of @code{^FOO} named @code{^BAR}, use the following command:
 5346: 
 5347: @example
 5348:   SET ^$JOB($JOB,"ALIASES","^BAR")="^FOO"
 5349: @end example
 5350: 
 5351: If such an alias is set, any reference to global variable @code{^BAR} will affect @code{^FOO} instead of @code{^BAR} until @code{^$JOB($JOB,"ALIASES","^BAR")} is @code{KILL}ed. If @code{^BAR} existed prior to the definition of this alias, its data will be unavailable to and unaffected by application code.  
 5352: 
 5353: @node Global Mappings
 5354: @chapter Global Mappings
 5355: @cindex mappings, global
 5356: @cindex globals, mapping
 5357: 
 5358: FreeM supports creating persistent mappings through which arbitrary global names may be mapped to specific namespaces. This allows non-@code{%} globals to be stored in the @code{SYSTEM} namespace, or @code{%} globals to be stored in non-@code{SYSTEM} namespaces.
 5359: 
 5360: To map the @code{^FOO} global to the @code{SYSTEM} namespace, any of the following will work:
 5361: 
 5362: @example
 5363:   MAP GLOBAL ^FOO="SYSTEM"
 5364:   SET ^$GLOBAL("FOO","NAMESPACE")="SYSTEM"
 5365:   SET ^$SYSTEM("MAPPINGS","GLOBAL","^FOO")="SYSTEM"
 5366: @end example
 5367: 
 5368: There is no functional difference in any of the three approaches; the method you choose is a matter of personal preference.
 5369: 
 5370: To remove the above mapping, any of the following examples will also work:
 5371: 
 5372: @example
 5373:   UNMAP GLOBAL ^FOO
 5374:   KILL ^$GLOBAL("FOO","NAMESPACE")
 5375:   KILL ^$SYSTEM("MAPPINGS","GLOBAL","^FOO")
 5376: @end example
 5377: 
 5378: 
 5379: 
 5380: @node Asynchronous Event Handling
 5381: @chapter Asynchronous Event Handling
 5382: @cindex event handling, asynchronous
 5383: 
 5384: Asynchronous event handling in FreeM follows the specifications of the unpublished MDC @emph{Millennium Draft Standard}.
 5385: 
 5386: @section Setting Up Async Event Handlers
 5387: 
 5388: Asynchronous event handlers are configured through the @code{^$JOB} structured system variable for job-specific events, and the @code{^$SYSTEM} structured system variable for system-wide events. In order to become proficient in writing asynchronous event handling code, you need to be aware of several important concepts:
 5389: 
 5390: @table @emph
 5391: 
 5392: @item Event Classes
 5393: @emph{Event classes} denote particular categories of events. These include @code{COMM}, @code{HALT}, @code{IPC}, @code{INTERRUPT}, @code{POWER}, @code{TIMER}, @code{TRIGGER}, and @code{USER} event classes. At present, only @code{INTERRUPT} and @code{TRIGGER} event classes are supported.
 5394: 
 5395: @item Event Identifiers
 5396: @emph{Event identifiers} denote the precise nature of the event that has occurred. For instance, resizing the terminal window in which a FreeM job is running will send an event of class @code{INTERRUPT} with an event identifier of @code{SIGWINCH} (short for @emph{SIGnal WINdow CHange}).
 5397: 
 5398: @item Event Handlers
 5399: @emph{Event handlers} are M routines or subroutines that can be registered to run when an event of a certain event class occurs.
 5400: 
 5401: @item Event Registration
 5402: @emph{Event registration} is the process of modifying the @code{^$JOB} or @code{^$SYSTEM} SSVN to associate a particular event class and event identifier with an event handler routine or subroutine.
 5403: 
 5404: @item Event Blocking and Unblocking
 5405: @emph{Event blocking} is the means by which asynchronous event handling can be temporarily suspended. For example, asynchronous events are temporarily and implicitly blocked for the duration of event handler execution, unless explicitly un-blocked within the event handler. Event handling can also be blocked and unblocked programatically from M code using the @code{ABLOCK} and @code{AUNBLOCK} commands.
 5406: 
 5407: @end table
 5408: 
 5409: The following sections of this chapter will take you step-by-step through setting up an event handler for @code{SIGWINCH} signal handling.
 5410: 
 5411: @section Registering an Asynchronous Event Handler
 5412: @cindex event handlers, registration
 5413: 
 5414: To register a job-specific event handler that will only execute in the current FreeM process, use the following syntax:
 5415: 
 5416: @example
 5417:   SET ^$JOB($JOB,"EVENT",@emph{event-class},@emph{event-identifier})=@emph{entryref}
 5418: @end example
 5419: 
 5420: To register a system-wide event handler that will execute in every FreeM process, use the following syntax:
 5421: 
 5422: @example
 5423:   SET ^$SYSTEM("EVENT",@emph{event-class},@emph{event-identifier})=@emph{entryref}
 5424: @end example
 5425: 
 5426: For example, use the following to register @code{^RESIZE} as an asynchronous event handler for @code{SIGWINCH} events:
 5427: 
 5428: @example
 5429:   SET ^$JOB($JOB,"EVENT","INTERRUPT","SIGWINCH")="^RESIZE"
 5430: @end example
 5431: 
 5432: This by itself will not enable asynchronous event handling, as it merely @emph{registers} an event handler, associating it with event class @code{INTERRUPT} and event identifier @code{SIGWINCH}.
 5433: 
 5434: @section Enabling Asynchronous Event Handling
 5435: @cindex event handlers, enabling
 5436: 
 5437: In order to enable asyncronous event handling, the @code{ASTART} command is used. In the following example, we will enable asynchronous event handling for the @code{INTERRUPT} event class:
 5438: 
 5439: @example
 5440:   ASTART "INTERRUPT"
 5441: @end example
 5442: 
 5443: Omitting the @code{"INTERRUPT"} argument will enable asynchronous event handling for @emph{all} event classes. See @code{ASTART} in the commands section for more details.
 5444: 
 5445: Once this is done, any event handlers registered for the @code{INTERRUPT} event class in @code{^$JOB} will be executed asynchronously as appropriate.
 5446: 
 5447: Please note that @code{ASTART "TRIGGER"} is run implicitly at FreeM startup, to ensure consistency in applications depending on business logic contained in system-wide global triggers. To disable this behavior, add @code{ASTOP "TRIGGER"} to the @code{LOCAL.STARTUP} routine in the @code{USER} namespace. If @code{LOCAL.STARTUP} does not yet exist in your environment, you may create it by typing @code{fmadm edit routine USER LOCAL.STARTUP} from your UNIX command-line shell.
 5448: 
 5449: @section Disabling Asynchronous Event Handling
 5450: @cindex event handlers, disabling
 5451: 
 5452: To disable asynchronous event handling, the @code{ASTOP} command is used. In the following example, we will disable asynchronous event handling for the @code{INTERRUPT} event class:
 5453: 
 5454: @example
 5455:   ASTOP "INTERRUPT"
 5456: @end example
 5457: 
 5458: Omitting the @code{"INTERRUPT"} argument will disable asynchronous event handling for @emph{all} event classes. See @code{ASTOP} in the commands section for more details.
 5459: 
 5460: You may also disable asynchronous event handling for a specific event identifier by @code{KILL}ing the appropriate node in the @code{^$JOB} SSVN, which unregisters the event handler altogether. The following example will unregister the event handler for the @code{SIGWINCH} event identifier:
 5461: 
 5462: @example
 5463:   KILL ^$JOB($JOB,"EVENT","INTERRUPT","SIGWINCH")
 5464: @end example  
 5465: 
 5466: @section Temporarily Blocking Asynchronous Event Handling
 5467: @cindex event handlers, blocking
 5468: 
 5469: To temporarily block processing of specific event classes, you will use the @code{ABLOCK} command. @code{ABLOCK} functions incrementally, that is, each successive call to @code{ABLOCK} will increment a counter of blocks held for the specified event class or classes, and each successive call to @code{AUNBLOCK} will decrement that counter. Event handling for the specified event classes will be blocked as long as the @code{ABLOCK} counter for those classes is greater than zero. Thus, event blocking is cumulative, in a manner similar to M incremental locks.
 5470: 
 5471: The following example blocks asynchronous event handling for the @code{INTERRUPT} event class:
 5472: 
 5473: @example
 5474:   ABLOCK "INTERRUPT"
 5475: @end example
 5476: 
 5477: Note that entering an event handler causes an implicit @code{ABLOCK} of @emph{all} event classes, to prevent event handlers from interrupting other event handlers during their execution. This may be overridden by calling @code{AUNBLOCK} for one or more event classes within an event handler. However, unblocking event handling during an event handler should be done with great caution, as this can make the flow of code execution somewhat unpredictable, especially if M globals are modified inside of an event handler routine or subroutine.
 5478: 
 5479: Modifying M globals within event handlers is allowed but strongly discouraged, as doing so can lead to logical corruption of the data. If you must modify an M global within an event handler, guard all such operations with prodigious and careful use of @code{LOCK}s, ensuring that such modifications occur in the desired logical order.
 5480: 
 5481: @node Global Triggers
 5482: @chapter Global Triggers
 5483: @cindex global triggers
 5484: @cindex triggers
 5485: 
 5486: Global triggers use the FreeM asynchronous event handling subsystem to allow a FreeM process to execute arbitrary M code when a particular action occurs on a particular global.
 5487: 
 5488: To set up a global trigger, you must set up an event handler for event class @code{TRIGGER}. The event identifier must be in the format of @code{"<action>:<gvn>"}, where @emph{<gvn>} is a global variable name, and @emph{<action>} is one of the following:
 5489: 
 5490: @table @asis
 5491: 
 5492: @item @code{DATA}
 5493: Trigger will fire when the @code{$DATA} intrinsic function is called on @emph{<gvn>}.
 5494: 
 5495: @item @code{GET}
 5496: Trigger will fire when @emph{<gvn>} is read from.
 5497: 
 5498: @item @code{INCREMENT}
 5499: Trigger will fire when intrinsic function @code{$INCREMENT} is called on @emph{<gvn>}.
 5500: 
 5501: @item @code{KILL}
 5502: Trigger will fire when @emph{<gvn>} is @code{KILL}ed.
 5503: 
 5504: @item @code{NEXT}
 5505: Trigger will fire when intrinsic function @code{$NEXT} is called on @emph{<gvn>}.
 5506: 
 5507: @item @code{ORDER}
 5508: Trigger will fire when intrinsic function @code{$ORDER} is called on @emph{<gvn>}.
 5509: 
 5510: @item @code{QUERY}
 5511: Trigger will fire when intrinsic function @code{$QUERY} is called on @emph{<gvn>}.
 5512: 
 5513: @item @code{SET}
 5514: Trigger will fire when @code{SET @emph{<gvn>}=@emph{value}} occurs.
 5515: 
 5516: @item @code{ZDATA}
 5517: Trigger will fire when intrinsic function @code{ZDATA} is called on @emph{<gvn>}.
 5518: 
 5519: @end table
 5520: 
 5521: When a @code{TRIGGER} event occurs, the @code{"GLOBAL"} node of the @code{^$EVENT} structured system variable will be populated with the global reference that invoked the trigger event.
 5522: 
 5523: If a @code{SET} or @code{KILL} trigger was the source of the @code{TRIGGER} event, the @code{OLD_VALUE} node of @code{^$EVENT} will be populated with original value of @code{^$EVENT("GLOBAL")} prior to the change, and @code{NEW_VALUE} will be populated with the new value. This allows triggers to contain logic to undo global changes. This functionality can also be used to provide auditing of specific global changes.
 5524: 
 5525: The following example shows a trigger implemented for @code{SET} operations on the @code{^DD} global.
 5526: 
 5527: @example
 5528: TRIGGER ;
 5529:     ;
 5530:     ; Set up a SET trigger on ^DD
 5531:     ;
 5532:     SET ^$JOB($JOB,"EVENT","TRIGGER","SET:^DD")="ONSET^TRIGGER"
 5533:     ;
 5534:     ; Enable the TRIGGER event class
 5535:     ;
 5536:     ASTART "TRIGGER"
 5537:     ;
 5538:     ; Try setting a node in ^DD
 5539:     ;
 5540:     SET ^DD(1)="Test"
 5541:     ;
 5542:     ; Quit
 5543:     ;
 5544:     QUIT
 5545:     ;
 5546:     ;
 5547: ONSET ;
 5548:     WRITE "The "_^$EVENT("GLOBAL")_" global node was SET.",!
 5549:     QUIT
 5550: @end example
 5551: 
 5552: You can also set up a trigger that applies to all FreeM processes by setting descendant subscripts of @code{^$SYSTEM("EVENT","TRIGGER",...)} instead of using @code{^$JOB($JOB,"EVENT","TRIGGER",...)}.
 5553: 
 5554: @node Synchronous Event Handling
 5555: @chapter Synchronous Event Handling
 5556: 
 5557: @node GUI Programming with MWAPI
 5558: @chapter GUI Programming with MWAPI
 5559: 
 5560: @node User-Defined Z Commands
 5561: @chapter User-Defined Z Commands
 5562: 
 5563: @node User-Defined Z Functions
 5564: @chapter User-Defined Z Functions
 5565: 
 5566: @cindex z functions, user-defined
 5567: 
 5568: @node User-Defined SSVNs
 5569: @chapter User-Defined SSVNs 
 5570: 
 5571: @cindex structured system variables, user-defined
 5572: @cindex structured system variables
 5573: 
 5574: @node Language Dialects
 5575: @chapter Language Dialects
 5576: 
 5577: @cindex language dialects
 5578: @cindex dialects, language
 5579: 
 5580: 
 5581: @node System Library Routines
 5582: @chapter System Library Routines
 5583: @cindex system library routines
 5584: 
 5585: @section ^%ZCOLUMNS
 5586: @cindex ^%ZCOLUMNS
 5587: @cindex system library routines, ^%ZCOLUMNS
 5588: 
 5589: This routine is the implementation of the @code{$ZCOLUMNS} intrinsic special variable.
 5590: 
 5591: @section %SYSINIT
 5592: @cindex %SYSINIT
 5593: @cindex system library routines, %SYSINIT
 5594: 
 5595: This routine is the default startup routine for FreeM running in direct mode.
 5596: 
 5597: Running @code{DO INFO} from direct mode will use this routine to display information about the current FreeM status and namespace configuration.
 5598: 
 5599: @section ^%ZHELP
 5600: @cindex ^%ZHELP
 5601: @cindex system library routines, ^%ZHELP
 5602: 
 5603: This routine implements the online help feature of FreeM, invoked by typing @code{?} in direct mode. It simply asks the underlying system to execute the command @command{info freem}.
 5604: 
 5605: @section ^%ZROWS
 5606: @cindex ^%ZROWS
 5607: @cindex system library routines, ^%ZROWS
 5608: 
 5609: This routine is the implementation of the @code{$ZROWS} intrinsic special variable.
 5610: 
 5611: @node Interrupt Handling
 5612: @chapter Interrupt Handling
 5613: @cindex interrupt handling
 5614: 
 5615: When FreeM receives the @code{SIGINT} signal, either by pressing @code{Ctrl-C} during program execution, or by external signal from the operating system, the FreeM environment daemon, or another external process, one of two things can happen, depending on the state of the @code{$ZI} special variable:
 5616: 
 5617: @table @asis
 5618: @item @code{$ZI} evaluates @emph{true}
 5619: In this case, the @code{ZINRPT} error is raised, and normal error handling procedures apply. If neither @code{$ZTRAP} nor @code{$ETRAP} are set, FreeM prints an error diagnostic on the home device and will exit the FreeM process in application mode (i.e., the @code{freem} executable was started with the @code{--routine} or @code{-r} flag), or return to the direct mode prompt otherwise.
 5620: 
 5621: This is the default behavior of FreeM.
 5622: @item @code{$ZI} evaluates @emph{false}
 5623: In this case, no error is raised, but the @code{$ZCONTROLC} flag is set. In this mode of operation, it is up to program code to check for @code{$ZCONTROLC} and take appropriate action.
 5624: 
 5625: Checking the value of @code{$ZCONTROLC} will reset it to @emph{false}.
 5626: @end table
 5627: 
 5628: In either case, if asynchronous event handling is enabled for the @code{INTERRUPT} event class (i.e., @code{ASTART "INTERRUPT"} or @code{ASTART} have been invoked by the current process), an asynchronous event of event class @code{INTERRUPT} and event identifier @code{SIGINT} will be enqueued. 
 5629: 
 5630: @node Error Processing
 5631: @chapter Error Processing
 5632: @cindex error processing
 5633: 
 5634: FreeM exposes three means of processing M program execution errors:
 5635: 
 5636: @table @emph
 5637: 
 5638: @item FreeM-style error processing
 5639: FreeM-style error processing exposes a read/write error trap in @code{$ZTRAP}. The contents of @code{$ZTRAP} must be either empty or a valid M entryref, to which FreeM will @code{GOTO} if an error occurs. Each program stack execution level can have its own @code{$ZTRAP} error handler enabled.
 5640: 
 5641: @item DSM 2.0-style error processing
 5642: DSM 2.0-style error processing emulates the @code{$ZTRAP} behavior of Digital Standard MUMPS v2. It has the same behavior as FreeM-style error handling, with the exception that in DSM 2.0-style error processing, only one @code{$ZTRAP} error handler is set across all program stack execution levels.
 5643: 
 5644: @item Standard error processing
 5645: Standard error processing uses the @code{NEW}-able @code{$ETRAP} variable to store error handler code, which may be any valid M code. The code in @code{$ETRAP} will run when an error occurs or the @code{$ECODE} ISV becomes non-empty. Stack information for standard error handling is provided by the @code{$STACK} ISV, the @code{$STACK()} intrinsic pseudo-function, and the @code{NEW}-able @code{$ESTACK} ISV.
 5646: 
 5647: If @code{$ETRAP} is non-empty when an error condition occurs, @code{$ZTRAP} is ignored, regardless of whether FreeM-style or DSM 2.0-style error processing is enabled at the time of the error.
 5648: 
 5649: @end table
 5650: 
 5651: For further information on switching between FreeM-style and DSM 2.0-style @code{$ZTRAP} error handling, see the documentation for the @code{BREAK} command.
 5652: 
 5653: @node FreeM Error Codes
 5654: @chapter FreeM Error Codes
 5655: @cindex Error Codes
 5656: 
 5657: @table @asis
 5658: 
 5659: @item @code{ZINRPT} - @emph{interrupt}
 5660: Raised when an interrupt signal is received.
 5661: 
 5662: @item @code{ZBKERR} - @emph{BREAK point}
 5663: Raised when a @code{BREAK} point is reached.
 5664: 
 5665: @item @code{ZNOSTAND} - @emph{non standard syntax}
 5666: Raised when features incompatible with the current value of @code{$DIALECT} are used.
 5667: 
 5668: @item @code{ZUNDEF} - @emph{variable not found}
 5669: Raised when an undefined local or global variable is accessed. This error code has been deprecated in favor of standard error codes @code{M6} and @code{M7}.
 5670: 
 5671: @item @code{ZLBLUNDEF} - @emph{label not found}
 5672: Raised when a referenced label is not found.
 5673: 
 5674: @item @code{ZMISSOPD} - @emph{missing operand}
 5675: Raised when an operand is missing from an expression.
 5676: 
 5677: @item @code{ZMISSOP} - @emph{missing operator}
 5678: Raised when an operator is missing from an expression.
 5679: 
 5680: @item @code{ZILLOP} - @emph{unrecognized operator}
 5681: Raised when an unrecognized operator is encountered in an expression.
 5682: 
 5683: @item @code{ZQUOTER} - @emph{unmatched quotes}
 5684: Raised when unbalanced quotes are encountered.
 5685: 
 5686: @item @code{ZCOMMAER} - @emph{comma expected}
 5687: Raised when a comma is expected in program syntax but is not found.
 5688: 
 5689: @item @code{ZASSIGNER} - @emph{equals '=' expected}
 5690: Raised when an equals sign is expected in program syntax but is not found.
 5691: 
 5692: @item @code{ZARGER} - @emph{argument not permitted}
 5693: Raised when an argument is encountered in a syntactic position where arguments are not permitted.
 5694: 
 5695: @item @code{ZSPACER} - @emph{blank ' ' expected}
 5696: Raised when a space character is expected in program syntax but is not found.
 5697: 
 5698: @item @code{ZBRAER} - @emph{unmatched parentheses}
 5699: Raised when unbalanced parentheses are detected in program syntax.
 5700: 
 5701: @item @code{ZLVLERR} - @emph{level error}
 5702: Raised when a level error occurs.
 5703: 
 5704: @item @code{ZDIVER} - @emph{divide by zero}
 5705: Raised when program code attempts to divide by zero. Deprecated in favor of standard error code @code{M9}.
 5706: 
 5707: @item @code{ZILLFUN} - @emph{function not found}
 5708: Raised when program code attempts to call intrinsic or extrinsic functions that are not defined.
 5709: 
 5710: @item @code{ZFUNARG} - @emph{wrong number of function arguments}
 5711: Raised when an intrinsic or extrinsic function is called with the wrong number of arguments.
 5712: 
 5713: @item @code{ZZTERR} - @emph{ZTRAP error}
 5714: Raised when a @code{$ZTRAP} error occurs.
 5715: 
 5716: @item @code{ZNEXTERR} - @emph{$NEXT/$ORDER error}
 5717: Raised when an error occurs in @code{$NEXT} or @code{$ORDER}.
 5718: 
 5719: @item @code{ZSELER} - @emph{$SELECT error}
 5720: Raised when an error occurs in @code{$SELECT}
 5721: 
 5722: @item @code{ZCMMND} - @emph{illegal command}
 5723: Raised when program code attempts to execute an illegal command.
 5724: 
 5725: @item @code{ZARGLIST} - @emph{argument list incorrect}
 5726: Raised when the argument list supplied to an M language element does not match that language element's syntactic requirements.
 5727: 
 5728: @item @code{ZINVEXPR} - @emph{invalid expression}
 5729: Raised when an invalid expression is encountered.
 5730: 
 5731: @item @code{ZINVREF} - @emph{invalid reference}
 5732: Raised when an invalid variable reference is encountered.
 5733: 
 5734: @item @code{ZMXSTR} - @emph{string too long}
 5735: Raised when a string is encountered that exceeds @code{^$SYSTEM("STRING_MAX")}.
 5736: 
 5737: @item @code{ZTOOPARA} - @emph{too many parameters}
 5738: Raised when too many parameters are passed to a function or subroutine.
 5739: 
 5740: @item @code{ZNOPEN} - @emph{unit not open}
 5741: Raised when attempting to access an I/O channel that has not been opened.
 5742: 
 5743: @item @code{ZNODEVICE} - @emph{unit does not exist}
 5744: Raised when attempting to access a device that does not exist.
 5745: 
 5746: @item @code{ZPROTECT} - @emph{file protection violation}
 5747: Raised when attempting to access a file or device to which you do not have permission.
 5748: 
 5749: @item @code{ZGLOBER} - @emph{global not permitted}
 5750: Raised when attempting to use a global in a syntactic element where global variables are not permitted.
 5751: 
 5752: @item @code{ZFILERR} - @emph{file not found}
 5753: Raised when attempting to access a file that does not exist.
 5754: 
 5755: @item @code{ZPGMOV} - @emph{program overflow}
 5756: Raised when a program overflows the limits of a routine buffer.
 5757: 
 5758: @item @code{ZSTKOV} - @emph{stack overflow}
 5759: Raised when @code{DO}, @code{FOR}, or @code{XECUTE} nesting levels exceed the value in @code{^$SYSTEM("NESTLEVLS")}.
 5760: 
 5761: @item @code{ZSTORE} - @emph{symbol table overflow}
 5762: Raised when program code attempts to store too much data in the local symbol table. Should not occur unless symbol table auto-adjust is disabled.
 5763: 
 5764: @item @code{ZNOREAD} - @emph{file won't read}
 5765: Raised when program code attempts to read from an unreadable file.
 5766: 
 5767: @item @code{ZNOWRITE} - @emph{file won't write}
 5768: Raised when program code attempts to write to an unwritable file.
 5769: 
 5770: @item @code{ZNOPGM} - @emph{routine not found}
 5771: Raised when an attempt is made to load or execute a routine that does not exist in the current namespace.
 5772: 
 5773: @item @code{ZNAKED} - @emph{illegal naked reference}
 5774: Raised when an attempt is made to use an illegal naked reference.
 5775: 
 5776: @item @code{ZSBSCR} - @emph{illegal subscript}
 5777: Raised when an illegal subscript access is attempted.
 5778: 
 5779: @item @code{ZISYNTX} - @emph{insert syntax}
 5780: Raised when illegal insert syntax is used.
 5781: 
 5782: @item @code{ZDBDGD} - @emph{global data degradation}
 5783: Raised when corruption is detected in global data files.
 5784: 
 5785: @item @code{ZKILLER} - @emph{job kill signal}
 5786: Raised on a job kill signal.
 5787: 
 5788: @item @code{ZHUPER} - @emph{hangup signal}
 5789: Raised on a job hangup signal.
 5790: 
 5791: @item @code{ZMXNUM} - @emph{numeric overflow}
 5792: Raised when an assignment or expression result exceeds @code{$ZPRECISION}.
 5793: 
 5794: @item @code{ZNOVAL} - @emph{function returns no value}
 5795: Raised when a function does not return a value. Extrinsic functions must @code{QUIT} with a value.
 5796: 
 5797: @item @code{ZTYPEMISMATCH} - @emph{type mismatch}
 5798: Raised when a type mismatch occurs.
 5799: 
 5800: @item @code{ZMEMOV} - @emph{out of memory}
 5801: Raised when FreeM runs out of heap memory.
 5802: 
 5803: @item @code{ZNAMERES} - @emph{error in name resolution}
 5804: Raised when an attempted name resolution fails.
 5805: 
 5806: @item @code{ZSCKCREAT} - @emph{error creating socket}
 5807: Raised when an error occurs creating a socket for network I/O.
 5808: 
 5809: @item @code{ZSCKIFAM} - @emph{invalid address family (must be IPV4 or IPV6)}
 5810: Raised when the address family specified in an @code{OPEN} command for a socket I/O channel is not IPV4 or IPV6.
 5811: 
 5812: @item @code{ZSCKITYP} - @emph{invalid connection type (must be TCP or UDP)}
 5813: Raised when the connection type specified in an @code{OPEN} command for a socket I/O channel is not @code{TCP} or @code{UDP}.
 5814: 
 5815: @item @code{ZSCKIPRT} - @emph{invalid port number}
 5816: Raised when the port number specified in an @code{OPEN} command for a socket I/O channel is invalid. Valid TCP and UDP ports are in the range of 1-65535.
 5817: 
 5818: @item @code{ZSCKCERR} - @emph{connection error}
 5819: Raised when an error occurs on a @code{USE <channel>:/CONNECT} command.
 5820: 
 5821: @item @code{ZSCKAERR} - @emph{USE action invalid for connection type (possibly CONNECT on UDP socket?)}
 5822: Raised when an attempt is made to @code{USE <channel>:/CONNECT} on a UDP socket I/O channel. The UDP protocol is connectionless.
 5823: 
 5824: @item @code{ZSCKACON} - @emph{attempted to CONNECT an already-connected socket}
 5825: Raised when an attempt is made to @code{USE <channel>:/CONNECT} on a TCP socket I/O channel that is already connected.
 5826: 
 5827: @item @code{ZSCKNCON} - @emph{attempted to READ from a disconnected TCP socket}
 5828: Raised when an attempt is made to @code{READ} a TCP socket that has not yet been connected.
 5829: 
 5830: @item @code{ZSCKEOPT} - @emph{error setting socket options}
 5831: Raised when an error is encountered while setting socket options.
 5832: 
 5833: @item @code{ZSCKERCV} - @emph{error in READ from socket}
 5834: Raised when an error occurs in a socket I/O channel @code{READ}.
 5835: 
 5836: @item @code{ZSCKESND} - @emph{error in WRITE to socket}
 5837: Raised when an error occurs while attempting to @code{WRITE} to a socket I/O channel.
 5838: 
 5839: @item @code{ZNORPI} - @emph{^$ZRPI only supported on Raspberry Pi hardware}
 5840: Raised when an attempt is made to use the @code{^$ZRPI} structured system variable on a platform other than the Raspberry Pi single-board computer.
 5841: 
 5842: @item @code{ZCREDEF} - @emph{cannot redefine CONST}
 5843: Raised when attempts are made to redefine a @code{CONST} after its initial definition.
 5844: 
 5845: @item @code{ZCMODIFY} - @emph{cannot modify CONST}
 5846: Raised when attempts are made to change the value of a @code{CONST}.
 5847: 
 5848: @item @code{ZFILEXWR} - @emph{cannot open existing file for WRITE}
 5849: Raised when an attempt is made to open an existing file in write (but not append) mode.
 5850: 
 5851: @item @code{INEWMULT} - @emph{initializing NEW with multiple setarguments not supported}
 5852: Raised when you attempt to use multiple setarguments with initializing @code{NEW}, e.g. @code{NEW X=2,Y=3}.
 5853: 
 5854: @item @code{ZECODEINV} - @emph{invalid value for $ECODE}
 5855: Raised when attempts are made to set @code{$ECODE} to an invalid error code value. Obsolete and replaced by standard error code @code{M101}.
 5856: 
 5857: @item @code{ZASSERT} - @emph{programmer assertion failed}
 5858: Raised when an @code{ZASSERT} expression's result is not true.
 5859: 
 5860: @item @code{ZUSERERR} - @emph{user-defined error}
 5861: Raised when program code calls @code{THROW} with an error code argument for which the first character is @code{U}, or when @code{$ECODE} is set to an error code for which the first character is @code{U}.
 5862: 
 5863: Custom error messages for @code{ZUSERERR} may be set in @code{^$JOB($JOB,"USER_ERRORS",<user_error_code>)}, where @code{<user_error_code>} represents the custom error code.
 5864: 
 5865: For example:
 5866: 
 5867: @example
 5868: DEFAULT.USER> S ^$JOB($JOB,"USER_ERRORS","UBLACKHOLE")="black hole encountered"
 5869: 
 5870: 
 5871: DEFAULT.USER> THROW UBLACKHOLE
 5872: 
 5873: 
 5874: >> Error UBLACKHOLE:  black hole encountered in SYSTEM::^%SYSINIT  [$STACK = 0]
 5875: >> THROW UBLACKHOLE
 5876:                   ^
 5877: @end example
 5878: 
 5879: @item @code{ZSYNTERR} - @emph{syntax error}
 5880: Raised when a syntax error without a more specific error code is encountered.
 5881: 
 5882: @item @code{ZCTRLB} - @emph{break}
 5883: Pseudo-error used by the FreeM debugger. Not visibly raised in normal program operation.
 5884: 
 5885: @item @code{ZASYNC} - @emph{asynchronous interruption}
 5886: Pseudo-error used by the FreeM asynchronous events subsystem. Not visibly raised in normal program operation.
 5887: 
 5888: @item @code{M1} - @emph{naked indicator undefined}
 5889: Raised when an attempt is made to use a naked reference before the naked indicator is set.
 5890: 
 5891: @item @code{M2} - @emph{invalid combination with $FNUMBER code atom}
 5892: 
 5893: 
 5894: @item @code{M3} - @emph{$RANDOM seed less than 1}
 5895: 
 5896: 
 5897: @item @code{M4} - @emph{no true condition in $SELECT}
 5898: 
 5899: 
 5900: @item @code{M5} - @emph{line reference less than zero}
 5901: 
 5902: 
 5903: @item @code{M6} - @emph{undefined local variable}
 5904: 
 5905: 
 5906: @item @code{M7} - @emph{undefined global variable}
 5907: 
 5908: 
 5909: @item @code{M8} - @emph{undefined intrinsic special variable}
 5910: 
 5911: 
 5912: @item @code{M9} - @emph{divide by zero}
 5913: 
 5914: 
 5915: @item @code{M10} - @emph{invalid pattern match range}
 5916: 
 5917: 
 5918: @item @code{M11} - @emph{no parameters passed}
 5919: 
 5920: 
 5921: @item @code{M12} - @emph{invalid line reference (negative offset)}
 5922: 
 5923: 
 5924: @item @code{M13} - @emph{invalid line reference (line not found)}
 5925: 
 5926: 
 5927: @item @code{M14} - @emph{line level not 1}
 5928: 
 5929: 
 5930: @item @code{M15} - @emph{undefined index variable}
 5931: 
 5932: 
 5933: @item @code{M16} - @emph{argumented QUIT not allowed}
 5934: 
 5935: 
 5936: @item @code{M17} - @emph{argumented QUIT required}
 5937: 
 5938: 
 5939: @item @code{M18} - @emph{fixed length READ not greater than zero}
 5940: 
 5941: 
 5942: @item @code{M19} - @emph{cannot copy a tree or subtree onto itself}
 5943: 
 5944: 
 5945: @item @code{M20} - @emph{line must have a formal parameter list}
 5946: 
 5947: 
 5948: @item @code{M21} - @emph{algorithm specification invalid}
 5949: 
 5950: 
 5951: @item @code{M22} - @emph{SET or KILL to ^$GLOBAL when data in global}
 5952: 
 5953: 
 5954: @item @code{M23} - @emph{SET or KILL to ^$JOB for non-existent job number}
 5955: 
 5956: 
 5957: @item @code{M24} - @emph{change to collation algorithm while subscripted local variables defined}
 5958: 
 5959: 
 5960: @item @code{M26} - @emph{non-existent environment}
 5961: 
 5962: 
 5963: @item @code{M27} - @emph{attempt to rollback a transaction that is not restartable}
 5964: 
 5965: 
 5966: @item @code{M28} - @emph{mathematical function, parameter out of range}
 5967: 
 5968: 
 5969: @item @code{M29} - @emph{SET or KILL on structured system variable not allowed by implementation}
 5970: 
 5971: 
 5972: @item @code{M30} - @emph{reference to global variable with different collating sequence within a collating algorithm}
 5973: 
 5974: 
 5975: @item @code{M31} - @emph{control mnemonic used for device without a mnemonic space selected}
 5976: 
 5977: 
 5978: @item @code{M32} - @emph{control mnemonic used in user-defined mnemonic space which has no associated line}
 5979: 
 5980: 
 5981: @item @code{M33} - @emph{SET or KILL to ^$ROUTINE when routine exists}
 5982: 
 5983: 
 5984: @item @code{M35} - @emph{device does not support mnemonic space}
 5985: 
 5986: 
 5987: @item @code{M36} - @emph{incompatible mnemonic spaces}
 5988: 
 5989: 
 5990: @item @code{M37} - @emph{READ from device identified by empty string}
 5991: 
 5992: 
 5993: @item @code{M38} - @emph{invalid structured system variable subscript}
 5994: 
 5995: 
 5996: @item @code{M39} - @emph{invalid $NAME argument}
 5997: 
 5998: 
 5999: @item @code{M40} - @emph{call-by-reference in JOB actual parameter}
 6000: 
 6001: 
 6002: @item @code{M41} - @emph{invalid LOCK argument within a transaction}
 6003: 
 6004: 
 6005: @item @code{M42} - @emph{invalid QUIT within a transaction}
 6006: 
 6007: 
 6008: @item @code{M43} - @emph{invalid range value ($X, $Y}
 6009: 
 6010: 
 6011: @item @code{M44} - @emph{invalid command outside of a transaction}
 6012: 
 6013: 
 6014: @item @code{M45} - @emph{invalid GOTO reference}
 6015: 
 6016: 
 6017: @item @code{M56} - @emph{identifier exceeds maximum length}
 6018: 
 6019: 
 6020: @item @code{M57} - @emph{more than one defining occurrence of label in routine}
 6021: 
 6022: 
 6023: @item @code{M58} - @emph{too few formal parameters}
 6024: 
 6025: 
 6026: @item @code{M60} - @emph{illegal attempt to use an undefined SSVN}
 6027: 
 6028: 
 6029: @item @code{M101} - @emph{invalid value for $ECODE}
 6030: 
 6031: 
 6032: @item @code{M102} - @emph{synchronous and asynchronous event processing cannot be simultaneously enabled for the same event class}
 6033: 
 6034: 
 6035: @item @code{M103} - @emph{invalid event identifier}
 6036: 
 6037: 
 6038: @item @code{M104} - @emph{ETRIGGER event identifier for IPC event class does not match job process identifier}
 6039: 
 6040: 
 6041: @end table
 6042: 
 6043: 
 6044: @node System Configuration
 6045: @chapter System Configuration
 6046: @cindex configuration, system
 6047: 
 6048: @section Installing FreeM
 6049: @cindex installation
 6050: 
 6051: @subsection Installation Methods
 6052: 
 6053: FreeM allows the following installation methods:
 6054: @table @asis
 6055: @item Binary Repository
 6056: For recent versions of the Ubuntu and Debian distributions of GNU/Linux, we provide package repositories from which FreeM may easily be installed. See the @emph{FreeM Wiki} for more information, and @emph{https://packages.coherent-logic.com} for instructions.
 6057: 
 6058: If available, this is the simplest method of installing FreeM.
 6059: @item Binary Packages
 6060: We provide binary packages of FreeM for @emph{dpkg} and @emph{rpm}-based distributions of GNU/Linux, and @emph{pkgadd} packages for Solaris 8-10. If you cannot use repositories, this is the easiest option.
 6061: 
 6062: See @emph{https://freem.coherent-logic.com/binaries.cfm} for downloads and instructions.
 6063: @item Source Tarball
 6064: If you prefer installing from source, we recommend that you download the latest @emph{.tar.gz} file from @emph{https://freem.coherent-logic.com/downloads.cfm}, and follow these steps:
 6065: 
 6066: @example
 6067: $ gunzip freem-@emph{<version>}.tar.gz
 6068: $ tar xf freem-@emph{<version>}.tar
 6069: $ cd freem
 6070: $ ./configure # see the Build Configuration section for optional flags
 6071: $ make
 6072: $ sudo make install
 6073: @end example
 6074: 
 6075: Once this process has been completed, you may proceed to @emph{Initial Configuration}.
 6076: 
 6077: Installation from source archive is the most challenging but flexible supported option for advanced users.
 6078: @item CVS Repository
 6079: If you wish to try the bleeding-edge development version of FreeM, you may do so by following these steps:
 6080: 
 6081: @verbatim
 6082: $ cvs -d :pserver:anonymous@cvs.coherent-logic.com:/home/cvsroot co freem
 6083: $ cd freem
 6084: $ ./autogen.sh
 6085: $ ./configure # see the Build Configuration section for optional flags
 6086: $ make
 6087: $ sudo make install
 6088: @end verbatim
 6089: 
 6090: Once this process has been completed, you may proceed to @emph{Initial Configuration}.
 6091: 
 6092: This installation method is by far the most complicated, and is intended only for those who wish to contribute to FreeM development. It is not intended for end users, and no technical support will be provided.
 6093: 
 6094: See the @emph{Contributor Guide} on the @emph{FreeM Wiki} for more information.
 6095: @end table
 6096: @subsection Build Configuration
 6097: @cindex build configuration
 6098: 
 6099: When configuring FreeM with the supplied @code{configure} script, there are some FreeM-specific options that may be used to compile in optional features, or exclude default ones:
 6100: 
 6101: @table @asis
 6102: 
 6103: @item @code{--enable-mwapi} (EXPERIMENTAL)
 6104: Enables experimental support for the M Windowing API (ANSI @emph{X11.6-1995}) using the OSF/Motif widget toolkit. Requires that you have the @code{X11}, @code{Xt}, @code{ICE}, and @code{Xm} libraries, as well as all of their C header files.
 6105: 
 6106: Please consult your operating system's documentation for the correct commands to install the required libraries.
 6107: 
 6108: @emph{Example}
 6109: 
 6110: @example
 6111: $ ./configure --enable-mwapi
 6112: $ make
 6113: $ sudo make install
 6114: @end example
 6115: 
 6116: @item @code{--enable-newglobals} (EXPERIMENTAL)
 6117: Enables a new and modernized global handler. This global handler has a number of known bugs, and thus should be used with caution.
 6118: 
 6119: Note that global files created in the default global handler are incompatible with the new global handler, and vice-versa. You will need to back up and remove all globals in your environments when switching global handlers.
 6120: 
 6121: 
 6122: @emph{Example}
 6123: 
 6124: @example
 6125: $ ./configure --enable-newglobals
 6126: $ make
 6127: $ sudo make install
 6128: @end example
 6129: 
 6130: @end table
 6131: 
 6132: @subsection Initial Configuration
 6133: Once FreeM is installed, you will need to configure it:
 6134: 
 6135: @enumerate
 6136: @item Create a user and group, each named @emph{freem}, under which FreeM will run
 6137: @item Add any user accounts that will need to run FreeM to the @emph{freem} group
 6138: @item Have all users added in step 2 sign out and sign in for the new group membership to take effect 
 6139: @item Run @code{fmadm configure} with superuser privileges to create the @code{DEFAULT} environment with @code{SYSTEM} and @code{USER} namespaces and default after-image journal settings, and populate the bundled vendor routines
 6140: @item Run @code{fmadm start environment} with superuser privileges to start the @code{DEFAULT} environment
 6141: @item Make sure the environment is ready by running @code{fmadm status environment} with superuser privileges
 6142: @end enumerate
 6143: 
 6144: @subsubsection Creating Additional Environments
 6145: To create additional environments, do the following steps:
 6146: 
 6147: @enumerate
 6148: @item Create a new user and group for the environment @emph{(optional)}
 6149: @item Run @code{fmadm configure -e=@emph{<environment>} -u=@emph{<username>} -g=@emph{<groupname>} [-E=@emph{true|false}]} @emph{(the @code{-E} flag enables or disables the environment)}
 6150: @item Run @code{fmadm start environment -e=@emph{<environment>}} to start the environment
 6151: @item Run @code{fmadm status environment} to make sure the environment is healthy
 6152: @end enumerate
 6153: 
 6154: @subsubsection Additional Customization
 6155: 
 6156: See the FreeM @emph{environment catalog} at @code{@emph{$PREFIX}/etc/freem/env.conf}, and the @emph{fmadm}(1) @code{man} page for more information.
 6157: 
 6158: @emph{$PREFIX} represents the root location of your FreeM installation. This can be @code{/usr/local}, @code{/}, or others, depending on how FreeM was built and installed.
 6159: 
 6160: @node Accessing FreeM from C Programs
 6161: @chapter Accessing FreeM from C Programs
 6162: 
 6163: FreeM provides a library, @file{libfreem.so}, as well as corresponding header file @file{freem.h}, allowing C programmers to write programs that access FreeM globals, locals, structured system variables, subroutines, and extrinsic functions. This functionality can be used to implement language bindings and data access drivers for external systems.
 6164: 
 6165: In order to be used in your C programs, your C programs must link with @file{libfreem.so} and include @file{freem.h}. This will allow your C code access to the function prototypes, data structures, and constants required for calling the @file{libfreem.so} APIs.
 6166: 
 6167: You must exercise caution in developing programs that interface with FreeM through @file{libfreem.so} to ensure that all @file{libfreem.so} API calls are serialized, as FreeM and the @file{libfreem.so} library are neither thread-safe nor reentrant.
 6168: 
 6169: You must also avoid setting signal handlers for @code{SIGALRM}, as FreeM uses @code{SIGALRM} to manage timeouts for @command{LOCK}, @command{READ}, and @command{WRITE}.
 6170: 
 6171: @section freem_ref_t Data Structure
 6172: @cindex libfreem, data structures: freem_ref_t
 6173: 
 6174: The @code{libfreem} API uses a @code{struct} of type @code{freem_ref_t} in order to communicate state, pass in values, and return results.
 6175: 
 6176: The data structure, defined in @file{freem.h}, looks like this:
 6177: 
 6178: @verbatim
 6179: typedef struct freem_ref_t {
 6180: 
 6181:     /*
 6182:      * The 'reftype' field can be one of:
 6183:      * 
 6184:      *  MREF_RT_LOCAL
 6185:      *  MREF_RT_GLOBAL
 6186:      *  MREF_RT_SSV
 6187:      */
 6188:     short reftype;
 6189: 
 6190:     /*
 6191:      * The 'name' field is the name of the local variable,
 6192:      * global variable, or SSVN (without ^ or ^$).
 6193:      */
 6194:     char name[256];    
 6195: 
 6196:     /*
 6197:      * Returned data goes in a string, so you've got to figure out the
 6198:      * whole M canonical number thing yourself. Good luck. :-)
 6199:      */
 6200:     char value[STRLEN];   
 6201: 
 6202:     short status;
 6203: 
 6204:     unsigned int subscript_count;
 6205:     char subscripts[255][256];
 6206: 
 6207: } freem_ref_t;
 6208: @end verbatim
 6209: 
 6210: @emph{freem_ref_t Members}
 6211: 
 6212: @table @asis
 6213: @cindex libfreem, freem_ref_t.reftype
 6214: @item @option{reftype}
 6215: The @option{reftype} member determines whether we are operating on a local variable, a global variable, or a structured system variable. It may be set to any of following constants: @code{MREF_RT_LOCAL}, @code{MREF_RT_GLOBAL}, or @code{MREF_RT_SSV}.
 6216: 
 6217: @cindex libfreem, freem_ref_t.name
 6218: @item @option{name}
 6219: The @option{name} member contains the name of the global, local, or SSVN to be accessed. You @emph{must not} include leading characters, such as @code{^} or @code{^$}.
 6220: 
 6221: @cindex libfreem, freem_ref_t.value
 6222: @item @option{value}
 6223: This member contains the value read from or the value to be written to the global, local, or SSVN.
 6224: 
 6225: @cindex libfreem, freem_ref_t.status
 6226: @item @option{status}
 6227: This member gives us various API status values after the API call returns. In general, this value is also returned by each API function.
 6228: 
 6229: @cindex libfreem, freem_ref_t.subscript_count
 6230: @item @option{subscript_count}
 6231: The number of subscripts to be passed into the API function being called. This value represents the maximum index into the first dimension of the @code{subscripts} array.
 6232: 
 6233: @cindex libfreem, freem_ref_t.subscripts
 6234: @item @option{subscripts}
 6235: A two-dimensional array containing the subscripts to which we are referring in this API call. 
 6236: 
 6237: @end table
 6238: 
 6239: @section freem_ent_t Data Structure
 6240: @cindex libfreem, data structures: freem_ent_t
 6241: 
 6242: The @code{freem_function()} and @code{freem_procedure()} APIs in @code{libfreem} use the @code{freem_ent_t} struct in order to indicate the name of the entry point being called, any arguments being passed to it, and the return value of the called function (not used for @code{freem_procedure()}).
 6243: 
 6244: The data structure, defined in @file{freem.h}, looks like this:
 6245: 
 6246: @verbatim
 6247: typedef struct freem_ent_t {
 6248: 
 6249:     /* name of function or procedure entry point */
 6250:     char name[256];
 6251: 
 6252:     /* return value */
 6253:     char value[STRLEN];
 6254: 
 6255:     /* value of ierr on return */
 6256:     short status;
 6257: 
 6258:     /* argument count and array */
 6259:     unsigned int argument_count;
 6260:     char arguments[255][256];
 6261: 
 6262: } freem_ent_t;
 6263: @end verbatim
 6264: 
 6265: @emph{freem_ent_t Members}
 6266: 
 6267: @table @asis
 6268: 
 6269: @item @option{name}
 6270: @cindex libfreem, freem_ent_t.name
 6271: The @option{name} member contains the name of the extrinsic function or procedure to be called.
 6272: 
 6273: @cindex libfreem, freem_ent_t.value
 6274: @item @option{value}
 6275: This member contains the value returned by the function called. Not used by @code{freem_procedure()}. 
 6276: 
 6277: @cindex libfreem, freem_ent_t.status
 6278: @item @option{status}
 6279: This member gives us the value of @code{ierr} after the function or procedure call returns. The possible values of @code{ierr} are listed in @code{merr.h}.
 6280: 
 6281: @cindex libfreem, freem_ent_t.argument_count
 6282: @item @option{argument_count}
 6283: The number of arguments to be passed into the extrinsic function or procedure being called. This value represents the maximum index into the first dimension of the @code{arguments} array.
 6284: 
 6285: @cindex libfreem, freem_ent_t.arguments
 6286: @item @option{arguments}
 6287: A two-dimensional array containing the arguments to be passed into the extrinsic function or procedure being called.
 6288: 
 6289: @end table
 6290: 
 6291: @section freem_init()
 6292: @cindex libfreem, freem_init()
 6293: 
 6294: Initializes @code{libfreem} in preparation for calling other APIs.
 6295: 
 6296: @emph{Synopsis}
 6297: 
 6298: @code{pid_t freem_init(char *environment_name, char *namespace_name);}
 6299: 
 6300: @emph{Parameters}
 6301: 
 6302: @table @asis
 6303: @item @code{environment_name}
 6304: Specifies the environment to use.
 6305: @item @code{namespace_name}
 6306: Specifies the namespace to use.
 6307: @end table
 6308: 
 6309: @emph{Return Values}
 6310: 
 6311: Returns the process ID of the @code{libfreem} process on success, or @code{-1} on failure.
 6312: 
 6313: @emph{Example}
 6314: 
 6315: This example prompts the user to enter a FreeM namespace and then attempts to initialize @code{libfreem} to use the selected namespace.
 6316: 
 6317: @verbatim
 6318: #include <stdio.h>
 6319: #include <string.h>
 6320: #include <freem.h>
 6321: 
 6322: int main(int argc, char **argv, char **envp)
 6323: {
 6324:     char namespace[256];
 6325: 
 6326:     /* get the namespace name to use */
 6327:     printf("Enter FreeM namespace to use: ");
 6328:     fgets(namespace, 255, stdin);
 6329: 
 6330:     /* remove the trailing newline */
 6331:     namespace[strcspn(buffer, "\n")] = '\0';
 6332: 
 6333:     /* initialize libfreem using the provided namespace */
 6334:     if(freem_init("DEFAULT", namespace) == TRUE) {
 6335:         printf("\nSuccess\n");
 6336:     }
 6337:     else {
 6338:         printf("\nFailure\n");
 6339:     }
 6340:      
 6341:     return 0;
 6342: }
 6343: @end verbatim
 6344: 
 6345: @section freem_version()
 6346: @cindex libfreem, freem_version()
 6347: 
 6348: Returns the version of FreeM in use.
 6349: 
 6350: @emph{Synopsis}
 6351: 
 6352: @code{short freem_version(char *result);}
 6353: 
 6354: @emph{Parameters}
 6355: 
 6356: @table @asis
 6357: @item @code{result}
 6358: The @code{result} parameter is a pointer to a buffer in which the FreeM version information will be returned. The caller must allocate memory for this buffer prior to calling this API. It should be at least 20 bytes in length.
 6359: @end table
 6360: 
 6361: @emph{Return Value}
 6362: 
 6363: Returns @code{0}.
 6364: 
 6365: @emph{Example}
 6366: 
 6367: This example will display the FreeM version on standard output.
 6368: 
 6369: @verbatim
 6370: #include <stdio.h>
 6371: #include <string.h>
 6372: #include <freem.h>
 6373: 
 6374: int main(int argc, char **argv, char **envp)
 6375: {
 6376:     char version[20] = {0};
 6377: 
 6378:     freem_init(``USER'');
 6379:     freem_version(version);
 6380: 
 6381:     printf(``FreeM version:  %s\n'', version);
 6382: 
 6383: }
 6384: @end verbatim
 6385: 
 6386: @section freem_set()
 6387: @cindex libfreem, freem_set()
 6388: 
 6389: Sets a FreeM local node, global node, or writable SSVN node. 
 6390: 
 6391: @emph{Synopsis}
 6392: 
 6393: @code{short freem_set(freem_ref_t *ref);}
 6394: 
 6395: @emph{Parameters}
 6396: 
 6397: @table @asis
 6398: @item @code{freem_ref_t}
 6399: This parameter is a pointer to a @code{freem_ref_t} struct. The caller must allocate the memory for this struct.
 6400: @end table
 6401: 
 6402: @emph{Return Value}
 6403: 
 6404: Returns @code{OK} on success, or one of the other error values defined in @code{merr.h}.
 6405: 
 6406: @emph{Example}
 6407: 
 6408: This example sets the value @code{blue} into global node @code{^car("color")}.
 6409: 
 6410: @verbatim
 6411: #include <stdio.h>
 6412: #include <string.h>
 6413: #include <freem.h>
 6414: 
 6415: int main(int argc, char **argv, char **envp)
 6416: {
 6417:     freem_ref_t ref;
 6418: 
 6419:     /* we're setting a global */
 6420:     ref.reftype = MREF_RT_GLOBAL;
 6421: 
 6422:     /* access global "car" */
 6423:     strcpy(ref.name, "car");
 6424: 
 6425:     /* set up the subscripts */
 6426:     ref.subscript_count = 1;
 6427:     strcpy(ref.subscripts[0], "color");
 6428:  
 6429: 
 6430:     /* use the USER namespace */
 6431:     freem_init("USER");
 6432: 
 6433:     /* write the data out */
 6434:     freem_set(&ref);
 6435:     
 6436: }
 6437: @end verbatim
 6438: 
 6439: @section freem_get()
 6440: @cindex libfreem, freem_get()
 6441: 
 6442: Retrieves a FreeM local node, global node, or writable SSVN node.
 6443: 
 6444: @emph{Synopsis}
 6445: 
 6446: @code{short freem_get(freem_ref_t *ref);}
 6447: 
 6448: @emph{Parameters}
 6449: 
 6450: @table @asis
 6451: @item @code{freem_ref_t}
 6452: This parameter is a pointer to a @code{freem_ref_t} struct. The caller must allocate the memory for this struct.
 6453: @end table
 6454: 
 6455: @emph{Return Value}
 6456: 
 6457: Returns @code{OK} on success, or one of the other error values defined in @code{merr.h}.
 6458: 
 6459: @emph{Example}
 6460: 
 6461: This example retrieves the character set of the current process.
 6462: 
 6463: @verbatim
 6464: #include <stdio.h>
 6465: #include <sys/types.h>
 6466: #include <unistd.h>
 6467: #include <string.h>
 6468: #include <freem.h>
 6469: 
 6470: int main(int argc, char **argv, char)
 6471: {
 6472:     pid_t pid;
 6473:     freem_ref_t ref;
 6474: 
 6475:     /* get the PID of this process */
 6476:     pid = getpid();
 6477: 
 6478:     /* we want to access an SSVN */
 6479:     ref.reftype = MREF_RT_SSV;
 6480:     
 6481:     /* set up the name and subscripts */
 6482:     strcpy(ref.name, "JOB");
 6483: 
 6484:     ref.subscript_count = 2;
 6485:     sprintf(ref.subscripts[0], "%d", pid);
 6486:     strcpy(ref.subscripts[1], "CHARACTER");
 6487: 
 6488:     /* initialize libfreem, using the USER namespace */
 6489:     freem_init("USER");
 6490: 
 6491:     /* call libfreem API */
 6492:     freem_get(&ref);
 6493: 
 6494:     /* output the character set info */
 6495:     printf("PID %d character set is '%s'\n", pid, ref.value);
 6496: }
 6497: @end verbatim
 6498: 
 6499: @section freem_kill()
 6500: @cindex libfreem, freem_kill()
 6501: 
 6502: Deletes a FreeM local node, global node, or killable SSVN node, as well as all of its children.
 6503: 
 6504: @emph{short freem_kill(freem_ref_t *ref);}
 6505: 
 6506: @emph{Parameters}
 6507: 
 6508: @table @asis
 6509: @item @code{freem_ref_t}
 6510: This parameter is a pointer to a @code{freem_ref_t} struct. The caller must allocate the memory for this struct.
 6511: @end table
 6512: 
 6513: @emph{Return Value}
 6514: 
 6515: Returns @code{OK} on success, or one of the other error values defined in @code{merr.h}.
 6516: 
 6517: @emph{Example}
 6518: 
 6519: @verbatim
 6520: #include <stdio.h>
 6521: #include <string.h>
 6522: #include <freem.h>
 6523: 
 6524: int main(int argc, char **argv, char **envp)
 6525: {
 6526:     freem_ref_t ref;
 6527: 
 6528:     /* we're killing a global node */
 6529:     ref.reftype = MREF_RT_GLOBAL;
 6530: 
 6531:     /* access global "car" */
 6532:     strcpy(ref.name, "car");
 6533: 
 6534:     /* set up the subscripts */
 6535:     ref.subscript_count = 0;
 6536: 
 6537:     /* use the USER namespace */
 6538:     freem_init("USER");
 6539: 
 6540:     /* kill the global and all its descendant subscripts */
 6541:     freem_kill(&ref);    
 6542: }
 6543: @end verbatim
 6544: 
 6545: @section freem_data()
 6546: @cindex libfreem, freem_data()
 6547: 
 6548: @section freem_order()
 6549: @cindex libfreem, freem_order()
 6550: 
 6551: @section freem_query()
 6552: @cindex libfreem, freem_query()
 6553: 
 6554: @section freem_lock()
 6555: @cindex libfreem, freem_lock()
 6556: 
 6557: @section freem_unlock()
 6558: @cindex libfreem, freem_unlock()
 6559: 
 6560: @section freem_tstart()
 6561: @cindex libfreem, freem_tstart()
 6562: 
 6563: @section freem_trestart()
 6564: @cindex libfreem, freem_trestart()
 6565: 
 6566: @section freem_trollback()
 6567: @cindex libfreem, freem_trollback()
 6568: 
 6569: @section freem_tlevel()
 6570: @cindex libfreem, freem_tlevel()
 6571: 
 6572: @section freem_tcommit()
 6573: @cindex libfreem, freem_tcommit()
 6574: 
 6575: @section freem_function()
 6576: @cindex libfreem, freem_function()
 6577: 
 6578: @section freem_procedure()
 6579: @cindex libfreem, freem_procedure()
 6580: 
 6581: @node FreeM Administrator
 6582: @appendix FreeM Administrator
 6583: @cindex utilities, system management
 6584: @cindex utilities, fmadm
 6585: @cindex fmadm
 6586: 
 6587: The @code{fmadm} utility is the preferred method of managing a FreeM installation, and will eventually replace all of the existing utilities.
 6588: In support of FreeM operators, @code{fmadm} presents a consistent, simple interface for all FreeM management tasks, and is namespace-aware.
 6589: This appendix will document each @code{fmadm} facility as it is implemented.
 6590: 
 6591: The @code{fmadm} utility's functions all follow the below, consistent syntax:
 6592: 
 6593: @example
 6594: usage:  fmadm <action> <object> <namespace> [OPTIONS]
 6595: @end example
 6596: 
 6597: The @emph{action} keyword can be one of the following:
 6598: 
 6599: @table @emph
 6600: 
 6601: @item list
 6602: Lists instances of @emph{object}
 6603: 
 6604: @item examine
 6605: Examines a single instance of @emph{object}
 6606: 
 6607: @item verify
 6608: Verifies the integrity of @emph{object}
 6609: 
 6610: @item compact
 6611: Compacts @emph{object}
 6612: 
 6613: @item repair
 6614: Repairs integrity problems in @emph{object}
 6615: 
 6616: @item create
 6617: Creates an instance of @emph{object}
 6618: 
 6619: @item remove
 6620: Removes an instance of @emph{object}
 6621: 
 6622: @item import
 6623: Imports an @emph{object}
 6624: 
 6625: @item export
 6626: Exports an @emph{object}
 6627: 
 6628: @item backup
 6629: Creates a backup of @emph{object}
 6630: 
 6631: @item restore
 6632: Restores a backup of @emph{object}
 6633: 
 6634: @item migrate
 6635: Migrates an instance of @emph{object} from an older FreeM version to the current version
 6636: 
 6637: @item edit
 6638: Edits an instance of @emph{object}
 6639: 
 6640: @end table
 6641: 
 6642: The @emph{object} keyword can be one of the following:
 6643: 
 6644: @table @emph
 6645: 
 6646: @item lock
 6647: The FreeM @code{LOCK} table.
 6648: 
 6649: Supported actions are @code{list} and @code{remove}.
 6650: 
 6651: @item journal
 6652: FreeM after-image journaling.
 6653: 
 6654: Supported actions are @code{examine} and @code{restore}.
 6655: 
 6656: The @code{examine} action will dump the after-image journal entries for the selected namespace in human-readable format.
 6657: 
 6658: The @code{restore} action will play after-image journals forward for the selected namespace.
 6659: 
 6660: @item namespace
 6661: FreeM namespaces (collections of M routines and globals).
 6662: 
 6663: No actions yet implemented.
 6664: 
 6665: @item global
 6666: The data files representing each FreeM @emph{global}.
 6667: 
 6668: Supported actions are @code{list}, @code{examine}, @code{remove}, and @code{verify}.
 6669: 
 6670: @item routine
 6671: An M routine, stored as a @code{.m} file.
 6672: 
 6673: Supported actions are @code{list}, @code{examine}, @code{remove}, @code{import}, @code{export}, @code{backup}, and @code{edit}.
 6674: 
 6675: @item job
 6676: A UNIX process representing an instance of the FreeM runtime.
 6677: 
 6678: Supported actions are @code{list} and @code{examine}.
 6679: 
 6680: @end table
 6681: 
 6682: 
 6683: @node FreeM VIEW Commands and Functions
 6684: @appendix FreeM VIEW Commands and Functions
 6685: 
 6686: @section VIEW 16: Total Count of Error Messages/View Single Error Message
 6687: @cindex VIEW commands/functions, 16, total count of error messages/view single error message
 6688: 
 6689: Unknown semantics
 6690: 
 6691: @section VIEW 17: Intrinsic Z-Commands
 6692: @cindex VIEW commands/functions, 17, intrinsic Z-commands
 6693: 
 6694: Allows the user to retrieve or specify the list of intrinsic Z-commands that FreeM will attempt to run internally, allowing intrinsic Z-commands implemented internally to be replaced with M equivalents implemented as %-routines in the @code{SYSTEM} namespace.
 6695: 
 6696: @section VIEW 18: Intrinsic Z-Functions
 6697: @cindex VIEW commands/functions, 18, intrinsic Z-functions
 6698: 
 6699: Allows the user to retrieve or specify the list of intrinsic Z-functions that FreeM will attempt to run internally, allowing intrinsic Z-functions implemented internally to be replaced with M equivalents implemented as %-routines in the @code{SYSTEM} namespace.
 6700: 
 6701: @section VIEW 19: Intrinsic Special Variables
 6702: @cindex VIEW commands/functions, 19, intrinsic special variables
 6703: 
 6704: Allows the user to retrieve or specify which special variables are implemented internally.
 6705: 
 6706: @section VIEW 20: Break Service Code
 6707: @cindex VIEW commands/functions, 20, break service code
 6708: 
 6709: Allows the user to view or specify the code that will be run when a @code{BREAK} is encountered.
 6710: 
 6711: @section VIEW 21: View Size of Last Global
 6712: @cindex VIEW commands/functions, 21, view size of last global
 6713: 
 6714: Allows the user to view the size of the last referenced global.
 6715: 
 6716: @section VIEW 22: Count VIEW 22 Aliases
 6717: @cindex VIEW commands/functions, 22, count VIEW 22 aliases
 6718: 
 6719: Retrieves the number of VIEW 22 aliases in effect.
 6720: 
 6721: @section VIEW 23: View Contents of Input Buffer
 6722: @cindex VIEW commands/functions, 23, input buffer contents
 6723: 
 6724: Retrieves the contents of the I/O input buffer.
 6725: 
 6726: @section VIEW 24: Maximum Number of Screen Rows
 6727: @cindex VIEW commands/functions, 24, maximum number of screen rows
 6728: 
 6729: Retrieves the maximum number of screen rows supported in the current FreeM build.
 6730: 
 6731: @section VIEW 25: Maximum Number of Screen Columns
 6732: @cindex VIEW commands/functions, 25, maximum number of screen columns
 6733: 
 6734: Retrieves the maximum number of screen columns supported in the current FreeM build.
 6735: 
 6736: @section VIEW 26: DO/FOR/XECUTE Stack Pointer
 6737: @cindex VIEW commands/functions, 26, DO/FOR/XECUTE stack pointer
 6738: 
 6739: Retrieves the @code{DO}, @code{FOR}, and @code{XECUTE} stack pointer.
 6740: 
 6741: @section VIEW 27: DO/FOR/XECUTE Stack Pointer (On Error)
 6742: @cindex VIEW commands/functions, 27, DO/FOR/XECUTE stack pointer, on error
 6743: 
 6744: Retrieves the @code{DO}, @code{FOR}, and @code{XECUTE} stack pointer (on error).
 6745: 
 6746: @section VIEW 29: Copy Symbol Table
 6747: @cindex VIEW commands/functions, 29, copy symbol table
 6748: 
 6749: Copies the symbol table? We aren't currently aware of what this means.
 6750: 
 6751: @section VIEW 30: Inspect Arguments
 6752: @cindex VIEW commands/functions, 30, inspect arguments
 6753: 
 6754: Retrieves the arguments passed to the @code{freem} executable.
 6755: 
 6756: @section VIEW 31: Count Environment Variables
 6757: @cindex VIEW commands/functions, 31, count environment variables
 6758: 
 6759: Allows the user to inspect the number of variables in the process environment table.
 6760: 
 6761: @emph{Syntax}
 6762: 
 6763: @example
 6764: WRITE $VIEW(31),!
 6765: @end example
 6766: 
 6767: @node Implementation Limits
 6768: @appendix Implementation Limits
 6769: 
 6770: @cindex limitations, memory
 6771: @cindex maximum size, routine
 6772: @cindex maximum size, global
 6773: @cindex maximum size, string
 6774: 
 6775: @node US-ASCII Character Set
 6776: @appendix US-ASCII Character Set
 6777: 
 6778: @multitable {Code} {Character} 
 6779: @item Code @tab Character
 6780: @item 000 @tab @code{<NUL>}
 6781: @item 001 @tab @code{<SOH>}
 6782: @item 002 @tab @code{<STX>}
 6783: @item 003 @tab @code{<ETX>}
 6784: @item 004 @tab @code{<EOT>}
 6785: @item 005 @tab @code{<ENQ>}
 6786: @item 006 @tab @code{<ACK>}
 6787: @item 007 @tab @code{<BEL>}
 6788: @item 008 @tab @code{<BS>}
 6789: @item 009 @tab @code{<HT>}
 6790: @item 010 @tab @code{<LF>}
 6791: @item 011 @tab @code{<VT>}
 6792: @item 012 @tab @code{<FF>}
 6793: @item 013 @tab @code{<CR>}
 6794: @item 014 @tab @code{<SO>}
 6795: @item 015 @tab @code{<SI>}
 6796: @item 016 @tab @code{<DLE>}
 6797: @item 017 @tab @code{<DC1>}
 6798: @item 018 @tab @code{<DC2>}
 6799: @item 019 @tab @code{<DC3>}
 6800: @item 020 @tab @code{<DC4>}
 6801: @item 021 @tab @code{<NAK>}
 6802: @item 022 @tab @code{<SYN>}
 6803: @item 023 @tab @code{<ETB>}
 6804: @item 024 @tab @code{<CAN>}
 6805: @item 025 @tab @code{<EM>}
 6806: @item 026 @tab @code{<SUB>}
 6807: @item 027 @tab @code{<ESC>}
 6808: @item 028 @tab @code{<FS>}
 6809: @item 029 @tab @code{<GS>}
 6810: @item 030 @tab @code{<RS>}
 6811: @item 031 @tab @code{<US>}
 6812: @item 032 @tab @code{<space>}
 6813: @item 033 @tab !
 6814: @item 034 @tab ``
 6815: @item 035 @tab #
 6816: 
 6817: 
 6818: @end multitable
 6819: 
 6820: @node FreeM Project Coding Standards
 6821: @appendix FreeM Project Coding Standards
 6822: 
 6823: @section Module Headers
 6824: @cindex coding standards, module headers
 6825: 
 6826: Module headers should adhere to the following format (where @code{Dollar} should be replaced with a dollar sign):
 6827: 
 6828: @verbatim
 6829: /*
 6830:  *   DollarIdDollar
 6831:  *    Function prototypes, structs, and macros for FreeM
 6832:  *    binding library
 6833:  *
 6834:  *  
 6835:  *   Author: Serena Willis <snw@coherent-logic.com>
 6836:  *    Copyright (C) 1998 MUG Deutschland
 6837:  *    Copyright (C) <Year> Coherent Logic Development LLC
 6838:  *
 6839:  *   This file is part of FreeM.
 6840:  *
 6841:  *   FreeM is free software: you can redistribute it and/or modify
 6842:  *   it under the terms of the GNU Affero Public License as published by
 6843:  *   the Free Software Foundation, either version 3 of the License, or
 6844:  *   (at your option) any later version.
 6845:  *
 6846:  *   FreeM is distributed in the hope that it will be useful,
 6847:  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 6848:  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 6849:  *   GNU Affero Public License for more details.
 6850:  *
 6851:  *   You should have received a copy of the GNU Affero Public License
 6852:  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
 6853:  *
 6854:  *   DollarLogDollar
 6855:  *
 6856:  * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
 6857:  * SPDX-License-Identifier: AGPL-3.0-or-later
 6858:  **/
 6859: @end verbatim
 6860: 
 6861: @section Variable Naming
 6862: @cindex coding standards, variable naming
 6863: 
 6864: Variables should be named in all lowercase letters, and words within them delimited by underscores, such as @code{my_useful_variable}. @code{PascalCase} and @code{camelCase} are not to be used in this codebase under any circumstances.
 6865: 
 6866: Constants defined via the C preprocessor should be in all uppercase letters, with words within them likewise delimited by underscores, such as:
 6867: 
 6868: @verbatim
 6869: #define MY_USEFUL_CONSTANT 1
 6870: @end verbatim
 6871: 
 6872: @section Indentation and General Layout
 6873: @cindex coding standards, indentation
 6874: @cindex coding standards, layout
 6875: 
 6876: This project uses four spaces for indentation. Tabs are not to be used under any circumstances, and all source files must use a linefeed character to delineate lines. If you are working on a Windows machine, you must take care to follow this, as Windows will use a carriage return followed by a linefeed by default.
 6877: 
 6878: This project follows a modified version of what is known as the Stroustrup indentation style.
 6879: 
 6880: @section Brace Placement (Functions)
 6881: @cindex coding standards, brace placement, functions
 6882: 
 6883: We use modern, ANSI-style function prototypes, with the type specifier on the same line as the function name. You may encounter other styles in the code, but we are transitioning to the new style as time permits.
 6884: 
 6885: Below is a correct example:
 6886: 
 6887: @verbatim
 6888: int main(int argc, char **argv, char **envp)
 6889: {
 6890: 
 6891: }
 6892: @end verbatim
 6893: 
 6894: @section Brace Placement (if-for-while-do)
 6895: @cindex coding standards, brace placement, if-for-while-do
 6896: 
 6897: The @code{if} keyword should be followed by one space, then the opening paren and conditional expression. We also use Stroustrup-style @code{else} blocks, rather than the K&R 'cuddled' @code{else}:
 6898: 
 6899: @verbatim
 6900: if (x) {
 6901: ...
 6902: }
 6903: else {
 6904: ...
 6905: }
 6906: 
 6907: while (1) {
 6908: ...
 6909: }
 6910: 
 6911: for (i = 1; i < 10; i++) {
 6912: ...
 6913: }
 6914: 
 6915: do {
 6916: ...
 6917: } while (x);
 6918: @end verbatim
 6919: 
 6920: Single-statement if blocks should be isolated to a single line:
 6921: 
 6922: @verbatim
 6923: if (x) stmt();
 6924: @end verbatim
 6925: 
 6926: not:
 6927: 
 6928: @verbatim
 6929: if (x)
 6930:     stmt ();
 6931: @end verbatim
 6932: 
 6933: Notice that there is a space between @code{if} and @code{(x)}, and also between @code{stmt} and @code{()}. This should be followed throughout the code.
 6934: 
 6935: If an @code{if} block has an @code{else if} or @code{else}, all parts of the construct must be bracketed, even if one or more of them contain only one statement:
 6936: 
 6937: @verbatim
 6938: if (x) {
 6939:     foo();
 6940: }
 6941: else if (y) {
 6942:     bar();
 6943: }
 6944: else {
 6945:     bas();
 6946: }
 6947: @end verbatim
 6948: 
 6949: @section Labels and goto
 6950: @cindex coding standards, labels
 6951: @cindex coding standards, goto
 6952: 
 6953: Labels must begin in column 1, and have two lines of vertical space above and one beneath.
 6954: 
 6955: @section Preprocessor Conditionals
 6956: @section coding standards, preprocessor conditionals
 6957: 
 6958: I have struggled with this, but have settled upon the standard practice of keeping them in column 1.
 6959: 
 6960: @section Overall Program Spacing
 6961: @cindex coding standards, spacing of programs
 6962: 
 6963: @itemize @bullet
 6964: @item
 6965: Variable declarations fall immediately beneath the opening curly brace, and should initialize the variable right there whenever initialization is used.
 6966: 
 6967: @item
 6968: One line between the last variable declaration and the first line of real code.
 6969: 
 6970: @item
 6971: The @code{return} statement of a function (when used as the last line of a function) should have one blank line above it and none below it.
 6972: 
 6973: @item
 6974: Really long functions (those whose entire body is longer than 24 lines) should have a comment immediately following the closing curly brace of the function, telling you what function the closing brace terminates.
 6975: @end itemize
 6976: 
 6977: @section The switch() Statement
 6978: @cindex coding standards, switch()
 6979: 
 6980: We indent @code{case} one level beneath @code{switch()}, and the code within each @code{case} beneath the @code{case}. Each @code{case} should have one line of vertical whitespace above it:
 6981: 
 6982: @verbatim
 6983: switch(foo) {
 6984: 
 6985:     case some_const:
 6986:         foo();
 6987: 
 6988:         break;
 6989: 
 6990:     case some_other_const:
 6991:         bar();
 6992: 
 6993:         break;	    
 6994: 
 6995:     default:
 6996:         exit(1);
 6997: 
 6998:         break;
 6999: }
 7000: @end verbatim
 7001: 
 7002: @section Comments
 7003: @cindex coding standards, comments
 7004: 
 7005: We use C-style comments (@code{/* comment */}) exclusively, even on single-line comments. C++ comments (@code{// comment}) are not permitted.
 7006: 
 7007: @node Index
 7008: @unnumbered Index
 7009: 
 7010: @printindex cp
 7011: 
 7012: @bye

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>