Annotation of freem/doc/freem.texi, revision 1.54

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

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