Rationale for Ada 2012
3.1 Overview of changes: Expressions
One of the key areas identified by the WG9 guidance
document
[1] as needing attention was
improving the ability to write and enforce contracts. These were discussed
in detail in the previous chapter.
When defining the new aspects for preconditions,
postconditions, type invariants and subtype predicates it became clear
that without more flexible forms of expressions, many functions would
need to be introduced because in all cases the aspect was given by an
expression.
However, declaring a function and thus giving the
detail of the condition, invariant or predicate in the function body
makes the detail of the contract rather remote for the human reader.
Information hiding is usually a good thing but in this case, it just
introduces obscurity.
Four forms are introduced, namely, if expressions,
case expressions, quantified expressions and expression functions. Together
they give Ada some of the flexible feel of a functional language.
In addition, membership tests are generalized to
allow greater flexibility which is particularly useful for subtype predicates.
The following Ada issues
cover the key changes and are described in detail in this chapter:
Qualified expressions and names
Conditional expressions
Generalizing membership tests
Quantified expressions
Expression functions
Case expressions
These changes can be grouped as follows.
First there are conditional expressions which come
in two forms, if expressions and case expressions, which have a number
of features in common (
147,
188).
Then there is the introduction of quantified expressions
which use
for all to describe a universal quantifier and
for
some to describe an existential quantifier. Note that
some
is a new reserved word (
176).
Next comes the fourth new form of expression which
is the expression function (
177).
Finally, membership tests are generalized (
158)
and there is a minor change regarding qualified expressions (
3).
© 2011, 2012, 2013 John Barnes Informatics.
Sponsored in part by: