[NAME] ALL.dao.operator [TITLE] Operators [DESCRIPTION] Dao Language supports a rich set of operators to facilitate the writing of more expressive scripts. Many of these operators can be used for different data types. Please note, in the following operators that involve one or more arrays, those operators are done in element-wise. 0.1 Arithmetic Operators 1 # Binary operators: 2 (int|float|double|complex|long|array) + (int|float|double|complex|long|array) # Addtion; 3 (int|float|double|complex|long|array) - (int|float|double|complex|long|array) # Subtraction; 4 (int|float|double|complex|long|array) * (int|float|double|complex|long|array) # Multiplication; 5 (int|float|double|complex|long|array) / (int|float|double|complex|long|array) # Division; 6 (int|float|double|complex|long|array) % (int|float|double|complex|long|array) # Modulo; 7 (int|float|double|complex|long|array) ** (int|float|double|complex|long|array) # Power; 8 9 #Unary operators: 10 + (int|float|double|complex|long|array) # Unary plus; 11 - (int|float|double|complex|long|array) # Unary minus; 12 ++ (int|float|double|complex|long|array) # Increment; 13 -- (int|float|double|complex|long|array) # Decrement; 0.2 Comparison Operators 1 (int|float|double|long) == (int|float|double|long) # Equal to; 2 (int|float|double|long) != (int|float|double|long) # Not equal to; 3 (int|float|double|long) < (int|float|double|long) # Less than; 4 (int|float|double|long) > (int|float|double|long) # Greater than; 5 (int|float|double|long) <= (int|float|double|long) # No greater than; 6 (int|float|double|long) >= (int|float|double|long) # No less than; 7 8 complex == complex # Equal to; 9 complex != complex # Not equal to; 10 11 array == array # Equal to; 12 array != array # Not equal to; 13 array(<int>|<float>|<double>) < array(<int>|<float>|<double>) # Less than; 14 array(<int>|<float>|<double>) > array(<int>|<float>|<double>) # Greater than; 15 array(<int>|<float>|<double>) <= array(<int>|<float>|<double>) # No greater than; 16 array(<int>|<float>|<double>) >= array(<int>|<float>|<double>) # No less than; 17 18 string == string # Equal to; 19 string != string # Not equal to; 20 string < string # Less than; 21 string > string # Greater than; 22 string <= string # No greater than; 23 string >= string # No less than; 0.3 Logic Operators 1 ! (int|float|double|long) # Logic negation (NOT); 2 not (int|float|double|long) # Logic negation (NOT); 3 4 (int|float|double|long) && (int|float|double|long) # Logic AND; 5 (int|float|double|long) and (int|float|double|long) # Logic AND; 6 (int|float|double|long) || (int|float|double|long) # Logic OR; 7 (int|float|double|long) or (int|float|double|long) # Logic OR; Note: And the and and or operator behave in the same way as the Lua and or operators, namely, the last evaluated operand is returned as the result. This means, when the first operand can determine the result, return the first operand, otherwise return the second. When the operands have values of 0 or 1, this behaviour is exactly the same as normal boolean logic. The following lists some examples for other cases, 1 10 && 0 # gives 0 2 0 && 10 # gives 0 3 10 && 20 # gives 20 4 20 && 10 # gives 10 5 6 10 || 0 # gives 10 7 0 || 10 # gives 10 8 10 || 20 # gives 10 9 20 || 10 # gives 20 Properly exploiting the behaviour of the and or operators can simplify coding for some cases. 0.4 Bitwise Operators 1 ~ (int|float|double|complex|long) # Bitwise NOT; 2 3 (int|float|double|long) & (int|float|double|long) # Bitwise AND; 4 (int|float|double|long) | (int|float|double|long) # Bitwise OR; 5 (int|float|double|long) ^ (int|float|double|long) # Bitwise XOR; 6 7 (int|float|double|long) << (int|float|double) # Bitwise left shift; 8 (int|float|double|long) >> (int|float|double) # Bitwise right shift; Please note, non-integer operands are converted to integers. 0.5 Compound assignment operators 1 (int|float|double) += (int|float|double) # Addition assignment; 2 (int|float|double) -= (int|float|double) # Subtraction assignment; 3 (int|float|double) *= (int|float|double) # Multiplication assignment; 4 (int|float|double) /= (int|float|double) # Division assignment; 5 (int|float|double) %= (int|float|double) # Modulo assignment 6 7 (int|float|double) &= (int|float|double) # Bitwise AND assignment; 8 (int|float|double) |= (int|float|double) # Bitwise OR assignment; 9 (int|float|double) ^= (int|float|double) # Bitwise XOR assignment; 10 11 long += (int|float|double|long) # Addition assignment; 12 long -= (int|float|double|long) # Subtraction assignment; 13 long *= (int|float|double|long) # Multiplication assignment; 14 long /= (int|float|double|long) # Division assignment; 15 long %= (int|float|double|long) # Modulo assignment 16 17 long &= (int|float|double|long) # Bitwise AND assignment; 18 long |= (int|float|double|long) # Bitwise OR assignment; 19 long ^= (int|float|double|long) # Bitwise XOR assignment; 20 21 array(<int>|<float>|<double>) += (int|float|double) # Addition assignment; 22 array(<int>|<float>|<double>) -= (int|float|double) # Subtraction assignment; 23 array(<int>|<float>|<double>) *= (int|float|double) # Multiplication assignment; 24 array(<int>|<float>|<double>) /= (int|float|double) # Division assignment; 25 array(<int>|<float>|<double>) %= (int|float|double) # Modulo assignment 26 27 array(<int>|<float>|<double>) += array(<int>|<float>|<double>) # Addition assignment; 28 array(<int>|<float>|<double>) -= array(<int>|<float>|<double>) # Subtraction assignment; 29 array(<int>|<float>|<double>) *= array(<int>|<float>|<double>) # Multiplication assignment; 30 array(<int>|<float>|<double>) /= array(<int>|<float>|<double>) # Division assignment; 31 array(<int>|<float>|<double>) %= array(<int>|<float>|<double>) # Modulo assignment 32 33 array<complex> += (int|float|double|complex|array) # Addition assignment; 34 array<complex> -= (int|float|double|complex|array) # Subtraction assignment; 35 array<complex> *= (int|float|double|complex|array) # Multiplication assignment; 36 array<complex> /= (int|float|double|complex|array) # Division assignment; 37 array<complex> %= (int|float|double|complex|array) # Modulo assignment 0.6 String operators 1 string + string # Concatenation; 2 string += int # Character appending; 3 string += string # String appending; 0.7 Type Operators 1 # Operators: ?= ?< 2 3 value1 ?= value2 # Type equal; 4 value ?< type # Is type of; 0.8 Ternery operator: ?: 1 expression1 ? expression2 : expression3 The value of expression2 is returned if expression1 is evaluated to true (non zero), otherwise the value of expression3 is returned. 0.9 Multiple Assignment: 1 ( C, A, B, ... ) = ( A, B, C, ... ) 2 ( A, B ) = func(); the expression in the right side should yield a list or tuple, and each of the elements in the tuple/list is assigned accordingly to each of the variables in the left side. Extra elements are ignored. 0.10 Miscellaneous operators 1 # Size operator: 2 % none # Data type size: 0; 3 % int # Data type size: 4 on 32 bits machine, or 8 on 64 bits machine; 4 % float # Data type size: 4 for single precision; 5 % double # Data type size: 8 for double precision; 6 % complex # Data type size: 16 (double precision for both parts); 7 % long # Number of digits in base 256; 8 % string # Number of characters; 9 % array # Number of elements; 10 % list # Number of items; 11 % map # Number of key-value pairs; 12 % tuple # Number of items; 13 14 # Complex conjugation operator: 15 ~ complex # Conjugation; 16 17 # "in" or "not in" operator: 18 int in string # Test if a character is in the string; 19 string in string # Test if the left operand is a substring of the right; 20 any in list # Test if a value is contained in a list; 21 any in map # Test if a key is in a map; 22 any in tuple # Test if a value is in a tuple; 23 24 int not in string # Test if a character is not in the string; 25 string not in string # Test if the left operand is not a substring of the right; 26 any not in list # Test if a value is not contained in a list; 27 any not in map # Test if a key is not in a map; 28 any not in tuple # Test if a value is not in a tuple;