Ordering
TinyAPL has a total array ordering, which means all arrays can be compared, for functions like Grade.
The ordering is as follows:
- two scalars are compared by their scalar value:
- two values of different types are ordered such that the one that appears first in this list is smaller;
- two numbers are compared first by their real part and then their imaginary part;
- two characters are compared by Unicode codepoint;
- two boxes are compared by comparing their contained arrays, as defined here;
- two wraps are compared by function comparison:
- two dfns are compared by their internal id, which is a number given to each dfn when it is created; note that the order in which the id is given to two dfns is undefined and therefore dfns should only be compared for equality;
- two primitive functions are compared by whether they're the same function;
- two derived adverbs are compared by first comparing the adverb and then the operand, with array operands going first;
- two derived conjunctions are compared by first comparing the conjunction, then the left operand and then the right operand, with array operands going first;
- two unwraps of function arrays are compared by the unwrapped array;
- two trains are compared by comparing their tines right to left.
- two adverb wraps are compared by adverb comparison:
- two dadvs are compared by their internal id with the same caveat as above;
- two primitive adverbs are compared by whether they're the same adverb;
- two adverb trains are compared by comparing their tines right to left.
- two conjunctions are compared by conjunction comparison:
- two dconjs are compared by their internal id with the same caveat as above;
- two primitive conjunctions are compared by whether they're the same conjunction;
- two conjunction trains are compared by comparing their tines right to left.
- two structs are incomparable and results are useless.
- two vectors are compared by comparing their contents in order; if they have uneven shape only the shared prefix is compared, and then the smaller array is the one with smaller shape;
- two arrays of different ranks are compared by promoting the one of lesser rank to the greater rank, and then breaking ties by comparing their rank;
- two arrays of higher rank are compared by comparing their major cells in order; if they have uneven tally only the shared prefix is compared, and then the smaller array is the one with smaller tally.