File:  [Coherent Logic Development] / freem / doc / freem.texi
Revision 1.43: download - view: text, annotated - select for diffs
Mon May 5 04:55:42 2025 UTC (10 months, 4 weeks ago) by snw
Branches: MAIN
CVS tags: HEAD
More manual fixes

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

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