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