mixed :add ( mixed &ARG , … )
mixed :+ ( mixed &ARG , … )
Takes any number of arguments. Performs addition between the rightmost pair of elements, then the second-rightmost, et cetera. Adds the value of the right element to the left one. Note that references will modify the values of variables.
Returns a copy of the value the leftmost argument ended up with.
The table below contains rules for adding values. Note that these rules are non-symmetrical; swapping the values may yield a different result. The row contains the type of the first (left) value in pair, while the column contains the type of the second (right) value in pair.
NIL | bool | bin | oct | int | hex | float | string | array | dict | |
---|---|---|---|---|---|---|---|---|---|---|
NIL | Arithmetics on NIL values have no effect. | |||||||||
bool | No effect. | Equal to a logical OR. | Bool is turned to TRUE if number is non-zero. | If absolute value of number is greater-or-equal to 1.0, bool becomes TRUE. | If string is true or contains a non-zero number, bool becomes TRUE. | Bool is set to TRUE if structure is non-empty. | ||||
bin | No effect. | Number is increased by 1 if bool is TRUE. | No type juggling needed. | Values are added, the result truncated and then put into integer. | String is converted to number (with regard to base). | Adds the number of entries in structure. | ||||
oct | ||||||||||
int | ||||||||||
hex | ||||||||||
float | No effect. | Number is increased by 1 if bool is TRUE. | Integer part is increased, fraction part remains unchanged. | No type juggling needed. | String is converted to float. | Float is increased by number of entries in structure. | ||||
string | No effect. | TRUE or FALSE is appended to string. | Text representation of number appended to string. No base-describing prefixes are attached. | Text representation of float is appended to string. | Strings are concatenated. | No effect. | ||||
array | Addition is performed on each structure element separately. | Addition is performed between keys present in both structures. | ||||||||
dict |
# :add example. :set &NUM i20 :writeln $NUM :add &NUM s'10' :writeln $NUM
wikipage modified on 2014/0601/2316