Multiple errors elicit but one report. If an error report in the following list is issued, then the ones preceding it do not apply. Five reports are common to all monadic operators:
- parse;
- value: an argument has no value;
- nondata: an argument (not an operand) is a function or some other nondata object;
- an error report from the operand function;
- wsfull: the workspace is currently not large enough to execute the function in; a bare left arrow (û), which dictates resumption of execution, causes the workspace to be enlarged if possible;
- interrupt (not an error): the user pressed c twice (once if A+ was started from a shell) while holding the Control key down.
g is a function scalar; that is, g is <{f} for some function f (other than Assignment). The arguments y and x are suitable arguments for f.Definition
The function f described in the arguments section is evaluated, as f x in the monadic case or as y f x in the dyadic case. Indeed, although the two infix forms are shown for definiteness, f{...} is evaluated for any valence of f, zero through nine.Additional Error ReportWarning! If instead of a function scalar you give a function expression, (e.g., instead of (+;-;«)[1]¡x or (<{f})¡x you give -¡x or f¡x), you will get a wrong result, namely, the result for the Each operator.
The following report is issued only if there is no parse or value error (see "Common Error Reports"):Examples
- a nonfunction error is reported if d is not a function scalar (or function expression: see the warning in the definition section); d precedes the colon in the error report.
fnsû(«;ß;Ò) ã Equivalent to <{«},<{ß},<{Ò} 2 3 fns[0]¡ 4 8 12 2 3 fns[1]¡ 4 0.5 0.75 2 3 fns[2]¡ 4 4 4 4 4 4 4
The operand f is Cast, And, Or, Not, or one of the six relational functions (< ¤ = ¦ > ¨). The arguments y and x are suitable arguments for f.Definition
The Bitwise operator applies Not to each bit of the argument and applies all the other functions except Cast to each pair of corresponding bits of the arguments.The derived function Bitwise Not is a monadic scalar function and all the others except Bitwise Cast are dyadic scalar functions, obeying the usual rules of conformability.
Examples for Bitwise Not, And, and Unequal
~® ¢16 15 ¢123 122
15 ¢16 122 ¢123 ã One's complement.5 ^® É10 0 1 0 1 4 5 4 5 0 1 5 ¨® É10 5 4 7 6 1 0 3 2 13 12And and Or, without the Bitwise operator, give boolean results for all valid arguments - see above.
Bitwise Cast ©®x
Since scalars of various types are represented using various numbers of bytes, the length of the last dimension of the result may differ from that of the right argument. There is no padding or truncation. If rb bytes are required to represent the result type and ab to represent the right argument type and rb>ra, then the last dimension of the right argument must be divisible by rbßab. The table below exhibits the relation between the shape of the right argument and that of the result.
The rank is changed only when a scalar is cast bitwise to a type that is represented in fewer bytes.
From `int | From `float | From `char | From `sym | |
---|---|---|---|---|
To `int | s | (¢1Õs), 2«¢1Ù1,s | (¢1Õs), (¢1Ùs)ß4 | s |
To `float | (¢1Õs), (¢1Ùs)ß2 | s | (¢1Õs), (¢1Ùs)ß8 | (¢1Õs), (¢1Ùs)ß2 |
To `char | (¢1Õs), 4«¢1Ù1,s | (¢1Õs), 8«¢1Ù1,s | s | (¢1Õs), 4«¢1Ù1,s |
Examples for Bitwise CastAdditional Report`int ©® ` 4163890 `int ©® 1.2 3.4 1072902963 858993459 1074475827 858993459 `char © `int ©® 'abcdefgh' dh ã Plain Cast converts just the last byte of an integer to character `char ©® `int ©® 'abcdefgh' abcdefgh `int ©® 'ab' ã[error] ©®: length ã The shape is 2, which is not divisible by 4.
- An "undefined" token report is issued if f is not one of the functions listed above.
f is any function expression (so Assignment is excluded, as it is for all operators). The result is nested. In the monadic case, the shape of the result is the shape of x. In the dyadic case, the shapes of the arguments and result follow the rules for dyadic scalar functions (see "Application, Conformability, and Result Shape"), except that only scalars are extended, not one-element arrays in general, and nonscalar arguments of differing ranks elicit a rank error report.Definition
The derived function, f¡, is a scalar function.Additional Error ReportsIn the case of monadic f:
(i#f¡x) ûý < f >i#xfor every valid index i. That is, each element of x is selected, f is applied to the Disclose of the selected element, and the result of f is enclosed and inserted in the result of f¡. (See "Disclose" for the definition of > and "Enclose" for <.) f¡x is equivalent to (f Each)x for the following defined operator Each:(f Each) x: { sûÒx; xû,x; zû(Òx)Ò<(); (iûÒz) do z[i]û< f >x[i]; sÒz}In the dyadic case, if x and y have the same shape, then(i#y f¡x) ûý <(>i#y)f>i#xfor every valid index i. If x has one element, then(i#y f¡x) ûý <(>i#y)f 0Øxfor every valid index i. (See "Pick" for the definition of Ø.) The definition is similar if y has one element, or both have one element.Warning! If instead of a function expression you give a function scalar, (e.g., instead of -¡x or f¡x you give (+;-;«)[1]¡x or (<{f})¡x), you will get a wrong result, namely, the result for the Apply operator.
Each of the following reports is issued only if there is no parse or value error (see "Common Error Reports") and none of the reports preceding it on this list applies:Examples
- a nonfunction error is reported if d is not a function expression (or function scalar: see the warning in the definition section); d precedes the colon in the error report;
- a rank error is reported, when the derived function is dyadic, if neither argument is a one-element array and their ranks differ;
- a length error is reported, when the derived function is dyadic, if neither argument is a one-element array and their shapes differ.
In the first expression, the Each operator is applied to a monadic function (Shape) to give the rank of a scalar, a vector, and a matrix. In the second, it is applied to a monadic (Count, to find the vector lengths) as well as to a dyadic (Take, to pad the vectors to equal lengths for the principal function, Disclose); notice the other use of Disclose to make the Count Each result simple for Max Reduce, which finds the greatest length.
ØÒ¡Ò¡ (2;É2;É2 3) 0 1 2 (Ó/>#¡vs)Ù¡vsû('ab';'----';'cde') ab ---- cde
f is one of +, «, Ä, Ó, ^, ©. The argument x is any array whose items are suitable left and right arguments of f. The shape of the result is 1ÕÒx.Definition
If #x is at least two, i.e., if x has at least two items, then f/x is defined to be:Additional Error Reportsx[0] f x[1] f ... f x[¢1+#x]If #x is one, then f/x is x; while if #x is zero, then f/x is (1ÕÒx)Òidentity, where identity is a scalar that depends on f, and whose type for + and « depends on x. See the table "Identity Scalars for Reduction".As pointed out in "Operators and Derived Functions", Reduce is not in the strictest sense an operator, but for most purposes it can be regarded as one.
Identity Scalars for Reduction
Function Identity + 0 « 1
Function Identity © 0 ^ 1
Function Identity Ó ¢Inf Ä Inf
If there is no error reported as a parse error then a similar error may be reported:Examples
The following report is issued only if there is no parse, token, or value error (see "Common Error Reports"):
- a token error is reported if f is a primitive function or operator symbol but not one of +«ÄÓ^©.
- a valence error is reported if f is a defined function (this report seems worth mentioning here, although it actually comes from Replicate - which of course also produces error reports and results when f is a variable).
+/3 5 ¢2 6 3+5+¢2 6 Ó/É6 2 10 11 +/É0 0
f is one of +, «, Ä, Ó, ^, ©. The argument x is any array whose items are suitable left and right arguments of f. The shape of the result is the same as the shape for x.Definition
If #x is at least one, i.e., if x has at least one item, then:Additional Error Reports(f\x)[i] ûý f/x[Éi+1]for every valid scalar index i. That is, Scan produces a sequence of moving reductions. If #x is zero, then f\x is empty, and its type is integer for ^ and © and depends upon x for the rest.As pointed out in "Operators and Derived Functions", Scan is not in the strictest sense an operator, but for most purposes it can be regarded as one.
If there is no error reported as a parse error then a similar error may be reported:Examples
The following report is issued only if there is no parse, token, or value error (see "Common Error Reports"):
- a token error is reported if f is a primitive function or operator symbol but not one of +«ÄÓ^©.
- a valence error is reported if f is a defined function (this report seems worth mentioning here, although it actually comes from Expand - which of course also produces error reports and results when f is a variable).
+\3 5 ¢2 3 8 6 Ä\É3 4 0 1 2 3 0 1 2 3 0 1 2 3 Ó\É3 4 0 1 2 3 4 5 6 7 8 9 10 11
doc@aplusdev.org | © Copyright 1995–2008 Morgan Stanley Dean Witter & Co. All rights reserved. |