## Language Reference - Operators

Operators are the symbols that you use to manipulate data items. eg In the expression A = B + C, the + operator acts on the data items B and C. The data items B and C are the operands. One of the unique features of the method language is its flexibility concerning the use of operators. You may apply an operator to any data item without regard to its type. If the operand is not the correct type, Equinox will automatically convert it. Consider the following:

- 2 + 2 equals 4
- 2 + "2" equals 4
- "2" + "2" equals 4

Similarly for subtract, multiply and divide. The string concatenation operator combines two strings:

- "Q" & "W" equals "QW"
- "2" & "2" equals "22"
- 2 & "2" equals "22"
- 2 & 2 equals "22"

The following table describes all of the operators that you can use. For each, the table includes the associated syntax convention, the returned value and the "priority" of the operator.

Operator | Syntax | Returned value | Priority |
---|---|---|---|

[ ] | X[Y] | Yth character in string X | 1 |

( ) | (X) | Enclosed expression | 2 |

(Unary Minus) | - X | Negative value of X | 3 |

(Unary plus) | + X | Positive value of X | 3 |

BinaryNot | BinaryNot X | One's complement of X | 3 |

BinaryAnd | X BinaryAnd Y | Contains bits which are 1 if both the matching bits in X and Y are 1 | 4 |

BinaryOr | X BinaryOr Y | Contains bits which are 1 if either of the matching bits in X and Y are 1 | 5 |

BianryXor | X BinaryXor Y | Contains bits which are 1 if the bits in X and Y are different | 5 |

^ | X ^ Y | X to power of Y | 6 |

Root | X Root Y | Y Root of X | 6 |

* | X * Y | X multiplied by Y | 7 |

/ | X / Y | X divided by Y | 7 |

Div | X Div Y | Integer result of X divided by Y | 7 |

Mod | X Mod Y | Remainder of X divided by Y | 7 |

+ | X + Y | Sum of X and Y | 8 |

- | X - Y | Difference of X and Y | 8 |

& | X & Y | X concatenated with Y | 9 |

To | X To Y | See following notes | 10 |

(List Expression) | - | See following notes | 11 |

(comma) | X, Y | See following notes | 12 |

>> | X >> Y | True is string X exists in string Y | 13 |

<< | X << Y | Performs a reverse search in string Y returning True if string X exists in string Y | 13 |

< | X < Y | True if X is less than Y | 13 |

ExistsIn | X ExistsIn Y | True is string X exists in string Y | 13 |

Contains | X Contains Y | True is string Y is contained in string X | 13 |

<= | X <= Y | True if X is less the or equal to Y | 13 |

= | X = Y | True if X is equal to Y | 13 |

<> | X <> Y | True if X is not equal to Y | 13 |

>= | X >= Y | True is X is greater than or equal to Y | 13 |

> | X > Y | True if X i greater than Y | 13 |

Not | Not X | True if X is False | 14 |

And | X And Y | True if X and Y are both True | 15 |

Or | X Or Y | True if either X or Y is True | 16 |

Xor | X Xor Y | True if either X or Y is True (not both) | 16 |

If an expression contains more than one operator, the order in which they are actioned is determined by their priorities. The smaller the priority number, the higher priority the operator takes. Operators with equal priority are actioned in the order in which they occur within the expression. eg Consider the following general expression:

A + B + 4 * C

The * operator is of a higher priority than +. C is multiplied by 4, A is added and then B.