Ada Programming/Operators

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

Ada Lovelace 1838.jpg

Standard operators[edit]

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]

and x \land y, (also keyword and)
or x \lor y, (also keyword or)
exclusive or (x \land \bar{y}) \lor (\bar{x} \land y), (also keyword xor)

Relational operators[edit]

Not Equal x \ne y, (also special character /=)
Equal x = y, (also special character =)
Less than x<y, (also special character <)
Less than or equal to (x \le y), (also special character <=)
Greater than (x > y), (also special character >)
Greater than or equal to (x \ge y), (also special character >=)

Binary adding operators[edit]

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

Unary adding operators[edit]

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

Multiplying operator[edit]

Multiply, x \times y, (also special character *)
Divide x / y, (also special character /)
modulus (also keyword mod)
remainder (also keyword rem)

Highest precedence operator[edit]

Power x^y, (also special character **)
logical not \lnot x, (also keyword not)
absolute value |x| (also keyword abs)

Short-circuit control forms[edit]

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]

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

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

Range membership test[edit]

if Today not in Tuesday .. Thursday then

Subtype membership test[edit]

Is_Non_Negative := X in Natural;

Class membership test[edit]

exit when Object in Circle'Class;

See also[edit]


Ada 95 Reference Manual[edit]

Ada 2005 Reference Manual[edit]

Ada Quality and Style Guide[edit]

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