File:  [Coherent Logic Development] / freem / doc / freem.texi
Revision 1.26: download - view: text, annotated - select for diffs
Fri Apr 18 03:59:29 2025 UTC (11 months, 2 weeks ago) by snw
Branches: MAIN
CVS tags: HEAD
Updates to texinfo manual

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

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