load help;


@[name]
dao.operator
@[name]

@[title]
Operators
@[title]


@[text]
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.

@[subsection]Arithmetic Operators@[subsection]
@[code]
# Binary operators:
(int|float|double|complex|long|array) +  (int|float|double|complex|long|array) # Addtion;
(int|float|double|complex|long|array) -  (int|float|double|complex|long|array) # Subtraction;
(int|float|double|complex|long|array) *  (int|float|double|complex|long|array) # Multiplication;
(int|float|double|complex|long|array) /  (int|float|double|complex|long|array) # Division;
(int|float|double|complex|long|array) %  (int|float|double|complex|long|array) # Modulo;
(int|float|double|complex|long|array) ** (int|float|double|complex|long|array) # Power;

#Unary operators:
+  (int|float|double|complex|long|array) # Unary plus;
-  (int|float|double|complex|long|array) # Unary minus;
++ (int|float|double|complex|long|array) # Increment;
-- (int|float|double|complex|long|array) # Decrement;
@[code]


@[subsection]Comparison Operators@[subsection]
@[code]
(int|float|double|long) == (int|float|double|long) # Equal to;
(int|float|double|long) != (int|float|double|long) # Not equal to;
(int|float|double|long) <  (int|float|double|long) # Less than;
(int|float|double|long) >  (int|float|double|long) # Greater than;
(int|float|double|long) <= (int|float|double|long) # No greater than;
(int|float|double|long) >= (int|float|double|long) # No less than;

complex == complex # Equal to;
complex != complex # Not equal to;

array == array # Equal to;
array != array # Not equal to;
array(<int>|<float>|<double>) <  array(<int>|<float>|<double>) # Less than;
array(<int>|<float>|<double>) >  array(<int>|<float>|<double>) # Greater than;
array(<int>|<float>|<double>) <= array(<int>|<float>|<double>) # No greater than;
array(<int>|<float>|<double>) >= array(<int>|<float>|<double>) # No less than;

string == string # Equal to;
string != string # Not equal to;
string <  string # Less than;
string >  string # Greater than;
string <= string # No greater than;
string >= string # No less than;
@[code]


@[subsection]Logic Operators@[subsection]
@[code]
!   (int|float|double|long) # Logic negation (NOT);
not (int|float|double|long) # Logic negation (NOT);

(int|float|double|long) &&  (int|float|double|long) # Logic AND;
(int|float|double|long) and (int|float|double|long) # Logic AND;
(int|float|double|long) ||  (int|float|double|long) # Logic OR;
(int|float|double|long) or  (int|float|double|long) # Logic OR;
@[code]
Note:
And the @[green]and@[green] and @[green]or@[green] operator behave in the same way as
the Lua @[green]and@[green] @[green]or@[green] 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,
@[code]
10 && 0  # gives 0
0  && 10 # gives 0
10 && 20 # gives 20
20 && 10 # gives 10

10 || 0  # gives 10
0  || 10 # gives 10
10 || 20 # gives 10
20 || 10 # gives 20
@[code]
Properly exploiting the behaviour of the @[green]and@[green] @[green]or@[green] operators 
can simplify coding for some cases.




@[subsection]Bitwise Operators@[subsection]
@[code]
~ (int|float|double|complex|long) # Bitwise NOT;

(int|float|double|long) & (int|float|double|long) # Bitwise AND;
(int|float|double|long) | (int|float|double|long) # Bitwise OR;
(int|float|double|long) ^ (int|float|double|long) # Bitwise XOR;

(int|float|double|long) << (int|float|double) # Bitwise left shift;
(int|float|double|long) >> (int|float|double) # Bitwise right shift;
@[code]
Please note, non-integer operands are converted to integers.


@[subsection]
Compound assignment operators
@[subsection]
@[code]
(int|float|double) += (int|float|double) # Addition assignment;
(int|float|double) -= (int|float|double) # Subtraction assignment;
(int|float|double) *= (int|float|double) # Multiplication assignment;
(int|float|double) /= (int|float|double) # Division assignment;
(int|float|double) %= (int|float|double) # Modulo assignment

(int|float|double) &= (int|float|double) # Bitwise AND assignment;
(int|float|double) |= (int|float|double) # Bitwise OR assignment;
(int|float|double) ^= (int|float|double) # Bitwise XOR assignment;

long += (int|float|double|long) # Addition assignment;
long -= (int|float|double|long) # Subtraction assignment;
long *= (int|float|double|long) # Multiplication assignment;
long /= (int|float|double|long) # Division assignment;
long %= (int|float|double|long) # Modulo assignment

long &= (int|float|double|long) # Bitwise AND assignment;
long |= (int|float|double|long) # Bitwise OR assignment;
long ^= (int|float|double|long) # Bitwise XOR assignment;

array(<int>|<float>|<double>) += (int|float|double) # Addition assignment;
array(<int>|<float>|<double>) -= (int|float|double) # Subtraction assignment;
array(<int>|<float>|<double>) *= (int|float|double) # Multiplication assignment;
array(<int>|<float>|<double>) /= (int|float|double) # Division assignment;
array(<int>|<float>|<double>) %= (int|float|double) # Modulo assignment

array(<int>|<float>|<double>) += array(<int>|<float>|<double>) # Addition assignment;
array(<int>|<float>|<double>) -= array(<int>|<float>|<double>) # Subtraction assignment;
array(<int>|<float>|<double>) *= array(<int>|<float>|<double>) # Multiplication assignment;
array(<int>|<float>|<double>) /= array(<int>|<float>|<double>) # Division assignment;
array(<int>|<float>|<double>) %= array(<int>|<float>|<double>) # Modulo assignment

array<complex> += (int|float|double|complex|array) # Addition assignment;
array<complex> -= (int|float|double|complex|array) # Subtraction assignment;
array<complex> *= (int|float|double|complex|array) # Multiplication assignment;
array<complex> /= (int|float|double|complex|array) # Division assignment;
array<complex> %= (int|float|double|complex|array) # Modulo assignment
@[code]



@[subsection]
String operators
@[subsection]

@[code]
string + string   # Concatenation;
string += int     # Character appending;
string += string  # String appending;
@[code]


@[subsection]
Type Operators
@[subsection]

@[code]
# Operators:  ?=  ?<

value1 ?= value2  # Type equal;
value  ?< type    # Is type of;
@[code]



@[subsection]
Ternery operator: ?:
@[subsection]

@[code]
expression1 ? expression2 : expression3
@[code]
The value of @[cyan]expression2@[cyan] is returned if @[cyan]expression1@[cyan]
is evaluated to true (non zero), otherwise the value of @[cyan]expression3@[cyan]
is returned.



@[subsection]Multiple Assignment:@[subsection]

@[code]
( C, A, B, ... ) = ( A, B, C, ... )
( A, B ) = func();
@[code]
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.


@[subsection]
Miscellaneous operators
@[subsection]

@[code]
# Size operator:
% none     # Data type size: 0;
% int      # Data type size: 4 on 32 bits machine, or 8 on 64 bits machine;
% float    # Data type size: 4 for single precision;
% double   # Data type size: 8 for double precision;
% complex  # Data type size: 16 (double precision for both parts);
% long     # Number of digits in base 256;
% string   # Number of characters;
% array    # Number of elements;
% list     # Number of items;
% map      # Number of key-value pairs;
% tuple    # Number of items;

# Complex conjugation operator:
~ complex  # Conjugation;

# "in" or "not in" operator:
int    in string  # Test if a character is in the string;
string in string  # Test if the left operand is a substring of the right;
any    in list    # Test if a value is contained in a list;
any    in map     # Test if a key is in a map;
any    in tuple   # Test if a value is in a tuple;

int    not in string  # Test if a character is not in the string;
string not in string  # Test if the left operand is not a substring of the right;
any    not in list    # Test if a value is not contained in a list;
any    not in map     # Test if a key is not in a map;
any    not in tuple   # Test if a value is not in a tuple;
@[code]

@[text]
