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