A+ script files are parsed from top to bottom when loaded, and all unresolved names are assumed to be variables. For example, suppose the following two lines appear in a script, in this order:f{x}:g Î x g{y}:y,' 'When this script is loaded, the definition of the function f is parsed before that of g, and therefore g is assumed to be a (global) variable in the definition of f, and the symbol Î is taken to be the dyadic primitive. Then the definition of g is parsed and it is determined that g is a function. When f is evaluated, a type error results because the dyadic primitive Î is passed a function as a left argument.f`abc Î: type * ©x ã Inquire about x `sym ã It's a symbol. * ©{g} `func ã But g is a function. * ýThis problem could have avoided by defining g before f. In general, however, and certainly in large applications, it is not reasonable (and sometimes not possible) to maintain scripts so that functions are always defined before they used. The problem could also be avoided by using the alternate function-call syntax; in the above example:f{x}:g{Î x}Now the A+ process can tell from the syntax that g is a monadic function, whether or not it has been defined. This syntax is unambiguous, whereas that of f in the original definition is ambiguous.
When an expression, expression group, or function definition is entered on several lines in an A+ session, A+ supplies stars at the left of each line to indicate the depth of punctuation. In general, these stars are used to indicate the total number of open quotation marks (at most one), braces, and parentheses, and an expression or function definition remains open until they are closed. Brackets are not treated in this way, however, and in the absence of an open quote, brace, or parenthesis a line or series of lines with an open bracket elicits an error message. Pressing the Enter key while inside a quotation mark inserts a newline character in the quoted string, but pressing Linefeed causes A+ to ignore all entries on the current line that follow the open quote (including the Linefeed itself).If any brackets, braces, or parentheses are open when a function definition is closed, a token error is reported and the definition does not take effect. At the time when such punctuation becomes isolated (e.g., after the closing parenthesis for the bracket in (3 4;bûd[1;3)), a message "Mismatched parentheses" (no matter what the punctuation - brackets, braces, or parentheses!) appears at the bottom of the screen in Emacs.
In immediate execution, when there is no pending punctuation or function definition, several expressions can be entered on one line, separated by semicolons. They will be treated as an expression group. The next section discusses the implications of this treatment for display.One useful aspect of this treatment is that one can bring into the workspace for immediate execution a script line which is only part of an expression group. Putting it another way, an expression group or part thereof can be brought in and executed immediately as long as its punctuation is matching - as long as it contains either both or neither of the group's enclosing braces.
An expression in braces, with no semicolon, also constitutes an expression group.
When an expression or expression group is entered for execution, by pressing the Enter key, an error message may be displayed. If it is not, then the result is displayed, except that it is not displayed for an expression whose last operation is Assign.The display of the Null is indistinguishable from no display, so in effect the displaying of the result can be suppressed for an expression or expression group by appending a semicolon to it, making the expression a courtesy expression group. Likewise, display can be forced for an expression alone on a line, even when it ends with Assign, by preceding the expression with a semicolon. (Preceding such an assignment in immediate execution by a Õ, thus applying Print to it, causes it to be displayed twice, once by Print and once as the default display of an expression whose last function is not Assign.)
For function and dependency definitions, there is no additional display: the entered definitions, together with the A+ prompts indicating depth of punctuation, are the entire displayed response.
Arrays are listed in ravel order. Simple character arrays start at the left margin. Simple numeric arrays are indented one space. Numbers that are in columns in the display are aligned. Simple vectors are displayed horizontally. Simple arrays of higher rank are displayed with vertical columns, horizontal rows, one skipped line between cells of rank 2, an extra skipped line between cells of rank 3, and so on. For example:É2 2 2 6 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47A < is used for a function scalar, since it must always be shown as an enclosed function expression. Furthermore, vectors of function scalars are displayed vertically. For example:<{+},<{-},<{=} < + ã Vector displayed vertically, with < showing enclosure of the < - ã function expressions, to make simple, depth-0 function scalars. < =Each nested component of a nested array begins on a new line. A < character is used to indicate the beginning of an enclosed object. It is also used sometimes to indicate a symbol, as shown above, but it is not so used in this manual except for that example. For instance:
(1 2 3; 2 2Ò25; (3 4;É2 3;<<100)) < 1 2 3 < 25 25 25 25 < < 3 4 < 0 1 2 3 4 5 < < < 100
When execution of a expression or function has been suspended because of an error or an interruption, expressions can be entered for immediate execution. (The expressions may include calls of other functions and may lead to suspensions of their own.) Values, shapes, types, etc. of both global variables and ones local to the suspended function may be examined and changed. The arguments on the stack (&0 &1 ...) can also be examined and changed. (Changing variables which were arguments to the suspended function has no effect on the stacked arguments.)To resume execution of the suspended function, with the workspace size increased if necessary, enter
û
alone on a line.To abandon execution, and execution of any pendent function that is waiting on this suspended function, enter either
ý
or
$
alone on a line.To abandon execution of the last n suspended functions, enter
$reset n
and to abandon execution of all suspended functions, enter just
$reset
See the Reset command.
Error reports are prefixed by a comment symbol and the type of report in brackets, to make it more explicit and also to prevent it from spoiling a part of a log that would otherwise be usable as a script:3+0ß5-5 ã[error] ß: domainã[error] segvandã PKG: 1: Storing .two ã See the package example.There are, however, some error messages that are not in this form, none of them strictly A+ error messages. Among them arefilename: No such file or directory not an `a objectand a great many messages from adap.
To help in avoiding name conflicts, A+ provides contexts. A context provides a level of qualification for global names. The fully qualified form of any global name is c.x, where x is the unqualified name of the object and c is the context for that name. Every name is accessible from every context by the use of its fully qualified form.The workspace always has one current context. Initially, at the beginning of an A+ session, it is the root context, whose name is the empty string. So .y is the form that a fully qualified name takes in this context. Such a name always refers to the root context. The current context can be changed by $cx cxt as discussed for the Context command; by convention, $cx . is used to change the current context to the root context - i.e., the context name is given as a period. In an expression entered for immediate execution, any unqualified name, no matter what its use - reference, specification, call, definition -, is understood to be implicitly qualified by the current context. Thus unqualified names can be used for objects whose full names are qualified by the current context.
To avoid clutter in the workspace and to reduce the possibility of name conflict, a name can be local - i.e., have meaning only in the function in which it occurs and disappear when execution of that function is complete. Such a name must be unqualified, and it is made local by an Assignment within the function in which only the name appears to the left of the arrow. All qualified names are global. See "Scope of Names".A function can see only global names and its own local names. A user can see only global names and the local names of the latest suspended function (and not pendent ones).
A visible use of a name occurs when the name appears in A+ code directly, and not in a character string or a symbol. A use that is not visible is an implicit reference, which occurs through the employment of Execute (â) or Value (%). This distinction is important for dependencies, which are invalidated only by visible uses of names (cf. "Dependencies", especially "Evaluation" and "Dependencies Defined").
System commands and system functions are provided for listing names of various kinds in the workspace:
- Commands described in "System Commands" include:
- Commands
- Context (gives context name)
- Contexts (all contexts in the workspace)
- Dependent Object Names
- External Functions
- (defined) Functions
- Global Objects
- (defined) Operators
- System Functions, and
- (user) Variables.
- Functions described in "System Functions", include:
- All Dependent Object Names
- Dependent Object Names, and
- Name List (user variables, functions and operators, dependencies, external functions, system variables, functions and commands, and contexts, as well as keywords and symbols).
A number of system functions and commands are available for inquiring about the active workspace:
- "System Commands" describes:
- Callback Flag
- Current Context
- All available Contexts
- Debugging State
- Execution Suspension Flag
- Input Mode
- Printing Precision
- Protected Execute Flag,
- State Indicator,
- Stop
- Terminal Flag
- Version
- Workspace Available, and
- X Events Flag.
- "System Functions" describes:
See also "Listing Names", above.
doc@aplusdev.org | © Copyright 19952001 Morgan Stanley Dean Witter & Co. All rights reserved. |