Ada Programming/Operators

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Ada. Time-tested, safe and secure.

Standard operators[edit | edit source]

Ada allows operator overloading for all standard operators and so the following summaries can only describe the suggested standard operations for each operator. It is quite possible to misuse any standard operator to perform something unusual.

Each operator is either a keyword or a delimiter—hence all operator pages are redirects to the appropriate keyword or delimiter.

Operators have arguments which in the RM are called Left and Right for binary operators, Right for unary operators (indicating the position with respect to the operator symbol).

The list is sorted from lowest precedence to highest precedence.

Logical operators[edit | edit source]

and
and , (also keyword and)
or
or , (also keyword or)
xor
exclusive or , (also keyword xor)

Relational operators[edit | edit source]

/=
Not Equal , (also special character /=)
=
Equal , (also special character =)
<
Less than , (also special character <)
<=
Less than or equal to (), (also special character <=)
>
Greater than (), (also special character >)
>=
Greater than or equal to (), (also special character >=)

Binary adding operators[edit | edit source]

+
Add , (also special character +)
-
Subtract , (also special character -)
&
Concatenate , & , (also special character &)

Unary adding operators[edit | edit source]

+
Plus sign , (also special character +)
-
Minus sign , (also special character -)

Multiplying operator[edit | edit source]

*
Multiply, , (also special character *)
/
Divide , (also special character /)
mod
modulus (also keyword mod)
rem
remainder (also keyword rem)

Highest precedence operator[edit | edit source]

**
Power , (also special character **)
not
logical not , (also keyword not)
abs
absolute value (also keyword abs)

Short-circuit control forms[edit | edit source]

These are not operators and thus cannot be overloaded.

and then
e.g. if Y /= 0 and then X/Y > Limit then ...
or else
e.g. if Ptr = null or else Ptr.I = 0 then ...

Membership tests[edit | edit source]

The Membership Tests also cannot be overloaded because they are not operators.

in
element of, , e.g. if I in Positive then, (also keyword in)
not in
not element of, , e.g. if I not in Positive then, (also keywords not in)

Range membership test[edit | edit source]

if Today not in Tuesday .. Thursday then
   ...

Subtype membership test[edit | edit source]

Is_Non_Negative := X in Natural;

Class membership test[edit | edit source]

exit when Object in Circle'Class;

See also[edit | edit source]

Wikibook[edit | edit source]

Ada 95 Reference Manual[edit | edit source]

Ada 2005 Reference Manual[edit | edit source]

Ada Quality and Style Guide[edit | edit source]


Ada Operators
and and then > + abs &
or or else >= - mod
xor = < * rem in
not /= <= ** / not in