TOM knows the following non-keyword operators, in increasing precedence.
=
*=, /=, %=, +=,
-=, <<=, >>=, >>>=, &=, |=,
^=, &&=, and ||=, share the precedence of =.
Assignment is right associative. Thus, a = b = 1 first assigns
1 to b and then assigns b to a.
? :
if else. If the types of the if and else
branches do not match, the type of the whole expression is void.
->
a -> b is identical to !a || b.
||
&&
<
<=
==
!=
>=
>
<, <=, =>,
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.
^
|
&
<<
>>
>>>
<< 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.
+
-
*
/
%
% 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.
[]
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.