The main purpose of this chapter is to describe the syntax of A+, but through a series of examples, rather than in a formal way. Consequently some commonly understood terms are used without being formally defined. In particular, the phrase A+ expression, or simply expression, is taken to have the same general meaning it does in mathematics, namely a well formed sentence that produces a value. In addition, some discussion of semantics has been included, but only where it seemed reasonable in order to complete a description. A brief discussion of well formed expressions is presented at the end of this section, after all the rules for the components of expressions have been presented.
A+ uses a mathematical symbol set to denote the functions that are native to the language, which are called primitive functions. This symbol set, part of the APL character set, consists of common mathematical symbols such as + and «, commonly used punctuation symbols, and specialized symbols such as Ù and Õ. In some cases it takes more than one symbol to represent a primitive function, as in +/, but the meaning can be deduced from the individual symbols. The symbols are listed in the table "Primitive Function and Operator Names and References".
User names fall into two categories, unqualified and qualified. An unqualified name is made up of alphanumeric (alphabetic and numeric) characters and underbars (_). The first character must be alphabetic. For example, a, a1c, and a_1c are unqualified names, but 3xy and _xy are not. (Although underbar is currently permitted as the first character in user names, this manual has been written as if it were not, and you should consider this form reserved for system names and avoid it.) The identifying words in control statements (case, do, else, if, while) are reserved by A+ for that use; they cannot appear as user names, even in qualified names.
System function names are unqualified names preceded by an underbar, with no intervening spaces, _argv for instance. The use of system function names is reserved by A+.The name of an object traditionally (and therefore in A+) called a system variable is an unqualified name preceded by a backquote, with no intervening spaces. For example, `rl is the name of the system variable called Random Link. These objects cannot be dealt with directly in A+, but only through certain system and primitive functions and system commands, to which they act as parameters. As indicated in "Symbols and Symbol Constants", they look just like symbols (and may be considered such). They are not, however, the symbol forms of names: A+ will not recognize rl, for instance, as having anything to do with `rl; the quoted form 'rl', however, is recognized by system functions such as _gsv.
System command names begin with a dollar sign, followed immediately by an unqualified name, which is the name of the command. The name is sometimes followed by a space and then by a sequence of characters whose meaning is specific to the command, usually separated from the name by a space.
Comments can appear either alone on a line or to the right of an expression. A comment is indicated by the ã symbol (usually called "lamp," since it looks like a bulb filament and since comments illuminate code), and it and everything to its right on the line constitute the comment. For example:a+b ã This is the A+ notation for addition.
A+ is a mathematical notation, and as such uses infix notation for primitive functions with two arguments. In infix notation, the symbol or user name for a function with two arguments appears between them. For example, a+b denotes addition, a-b subtraction, a«b multiplication, and aßb division.In mathematics, the symbol - can also be used with one argument, as in -b, in which case it denotes negation. This is true in A+ as well. Because the symbol denotes two functions, one with one argument and the other with two, it is called ambi-valent (e.g., it uses "both valences"). A+ has extended the idea of ambi-valence to most of its primitive functions. For example, just as -b denotes the negative of b, so ßb denotes the reciprocal of b.
Defined functions cannot be ambi-valent.
Individual numbers can be expressed in the usual integer, decimal, and exponential formats, with one exception: negative number constants begin with a "high minus" sign (¢) - including ¢Inf, which we will come to later - instead of the more conventional minus sign (-), although negative exponents in the exponential format are denoted by the conventional minus sign.
A character constant is expressed as a list of characters surrounded by a pair of single quote marks or a pair of double quote marks. For a quote mark of the same kind as the surrounding quote marks to be included in a list of characters, it must be doubled. For example, both 'abc''d' and "abc'd" are constant expressions for the list of characters abc'd. There is, however, a distinction between the two kinds of quotation marks.Within single quotes (') the C escape sequences and indeed any \c are not treated in any way, but left as is.
In strings contained within double quotes (") these sequences and \c are treated as follows:
These sequences and their translations are (where parenthesis indicates that A+ does not perform the substitution that the parenthesized term implies):
- \n is replaced by a newline character;
- \o, \oo, and \ooo (each o a digit) are replaced by a character (see below); and
- the other sequences simply have the leading backslash removed.