next up previous contents
Next: 6.7.1 The real type Up: 6. Programming Previous: 6.6 Evaluation   Contents


6.7 Operators

nip2's expression syntax is almost exactly the same as C, with a few small changes. Table 6.2 lists all of nip2's operators in order of increasing precedence. If you've used C, the differences are:

The only slightly tricky point is that function application binds very tightly (only list index and class project bind more tightly). So the expression:

                                                      
  jim = fred 2 + 3

binds as:

                                                      
  jim = (fred 2) + 3

This is almost always the behaviour you want.

There are two special equality tests: === and !==. These test for pointer equality, that is, they return true if their arguments refer to the same object. These are occasionally useful for writing interactive functions.


Table 6.2: nip2 operators in order of increasing precedence
Operator Associativity Description
if then else Right If-then-else construct
, Left List/complex separator
|| Left Logical or
&& Left Logical and
@   Function composition (see §6.7.6)
| Left Bitwise or
^ Left Bitwise exclusive or
& Left Bitwise and
== Left Equal to
!=   Not equal to
===   Pointer equal to
!==   Pointer not equal to
< Left Less than
<=   Less than or equal to
>   Greater than
>=   Greater than or equal to
« Left Left shift
»   Right shift
+ Left Addition
-   Subtraction
* Left Multiplication
$/$   Division
%   Remainder after division
! Left Logical negation
~   One's complement
++   Join (see §6.8)
-   Unary minus
+   Unary plus
(type)   Type cast expression
** Right Raise to power
:   List CONS (see §6.8)
space Left Function application
? Left List index (see §6.8)
. Left Class project (see §6.11)




Subsections
next up previous contents
Next: 6.7.1 The real type Up: 6. Programming Previous: 6.6 Evaluation   Contents
John Cupitt 2004-12-20