Go to the first, previous, next, last section, table of contents.


Operators

TOM knows the following non-keyword operators, in increasing precedence.

=
Assignment. The type of the rhs must match convertibly the lvalue lhs. All modifying assingments, *=, /=, %=, +=, -=, <<=, >>=, >>>=, &=, |=, ^=, &&=, and ||=, share the precedence of =.

Assignment is right associative. Thus, a = b = 1 first assigns 1 to b and then assigns b to a.

? :
Conditional expression with mandatory else branch. This really is syntactic sugar for if else. If the types of the if and else branches do not match, the type of the whole expression is void.
->
Implication. a -> b is identical to !a || b.
||
Short circuit boolean `or' operation. Both arguments must have a boolean type.
&&
Short circuit boolean `and' operation. Both arguments must have a boolean type.
<
<=
==
!=
>=
>
Comparisons. The ordering comparisons (<, <=, =>, and >) only operate on numeric-typed values. The equality comparisons (== and !=) operate on any type; they test the identicality of the arguments. Testing the equality of of two tuple-typed values tests the equality of all the elements, i.e. without short-circuits.
^
Boolean exclusive-or of boolean values or bitwise exclusive-or of integer numeric typed values.
|
Boolean or of boolean values or bitwise or of integer numeric typed values.
&
Boolean and of boolean values or bitwise and of integer numeric typed values.
<<
>>
>>>
Bitwise shifting of integer numeric types. << shifts left the number of bits specified by the rhs, >> shifts right, and >>> shifts right logically, as opposed to arithmetically. >>> is useful for `unsigned' shifts on the signed int and long typed values.
+
-
Numeric addition and subtraction.
*
/
%
Numeric multiplication and division. % is integer modulo.
~
!
-
~ is the inversion of a boolean value, or the bitwise inversion of an integer numeric value. ! extracts and then negates a truth value from any non-tuple typed value. It returns the boolean truth if the argument does has the default value for its type. - is the unary minus. It operates only on numeric types.
[]
Square brackets are syntactical sugar for array indexing. See section Array indexing.

Operations on numeric types are performed in the precision of the type of the result. Thus, adding two floats results in a float, adding a byte to an int results in an int, after the byte has implicitly been converted to an int.

Operators provide functionality which is statically bound.

[Note: They are actually special methods declared in the class _builtin_.Top. They are special since they can not be redeclared in any way, the syntax of TOM allowing neither a character like `+' in a method name nor a method with one namepart and two arguments. The operator methods are looked up in the class of the current object.

Thus, with a slightly bent syntax and ignoring the fact that not all objects have an isa as far as the compiler knows, a + b is actually a shorthand for [isa + a, b]. End note.]


Go to the first, previous, next, last section, table of contents.