Skip to content
Hub Nexus

No author yetClaim it

Version 1Updated 3 min read

Support

Computing » Computer Science » Computer Programming » Ada Programming

Expressions

The LRM defines an expression as a formula that defines the computation or retrieval of a value..[1] There are numerous forms of expression, ranging from primaries such as literals or names, to quantified expression.

An expression is typically used in an assignment, or as part of a bigger expression. The value of an expression usually involves computation. However, some expressions' values are determined at compile time; these are called static expressions. A so-called simple expression (which happens to be a term) is seen in

Area := Length * Height;

The text Length * Height has the form of an expression, and is used on the right hand side of an assignment statement. Computing the value of the expression means multiplying the value named Length by the one named Height. Using the same expression as part of a bigger expression is demonstrated in the following example:

if Cost (Paint, Area => Length * Height) > 900 * Dollar

The bigger expression starts with Cost and ends with Dollar. It features another form of expression, a relation, and places a function call and another multiplicative expression to the left and right, respectively, of the relation's relational operator >. The two are called operands and the result is a Boolean expression.

Kinds of Expressions

Among basic expressions are literals, for example, decimal (real), enumeration, string, and access value literals:

2.5e+3
False
"и"
null

Involving many of those, one can write aggregates (a primary),

(X => 0.0,
Y => 1.0,
Z => 0.0)

but arbitrarily complex sub-components are possible, too, creating an aggregate from component expressions,

(Height => 1.89 * Meter,
Age => Guess (Picture => Images.Load (Suspects, "P2012-Aug.PNG"),
Tiles => Grid'(1 .. 3 => Scan, 4 => Skip)),
Name => new Nickname'("Herbert"))

Age is associated with the value of a nested function call. The actual parameter for Tiles has type name Grid qualify the array aggregate following it; the component Name is associated with an allocator.

The well known ‘mathematical’ expressions have closely corresponding simple expressions in Ada syntax, for example 2.0πr, or the relation

Area = π*r**2

Other expressions test for membership in a range, or in a type:

X in 1 .. 10 | 12
Shape in Polygon'Class

Conditional Expressions, Quantified Expressions

New in Ada 2012, there are forms for making the value of an expression depend on the value of another expression, conditionally. They have a pair of parentheses around them and they start with a keyword, which clearly distinguishes them from other kinds of expression. For example:

Area := (if Is_Circular then Pi * Radius**2 else Length * Height);

In this example, the value of Is_Circular determines the part of the expression that is used for computing the value of the entire expression. A similar construct exists for case and also one for for. These kinds of expressions are frequently used in assertions, like in the conditions of contract based programming.

References

↑ Section 4: Expressions [Annotated]

Where this page came from

This page was imported from Wikibooks. From “Ada Programming” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

Comments

Spinner Logo

Next in Ada Programming

CC BY-SA 4.0
[Computing]( » [Computer Science]( » [Computer Programming]( » [Ada Programming]( This computer programming article is available for [pseudocode]( Ada, and [ooc]( ## Conditionals Conditional clauses are blocks of code that will only execute if a particular expression (the condition) is [true]( ### i
CC BY-SA 4.0
Ada Programming, Type System
CC BY-SA 4.0
[Computing]( » [Computer Science]( » [Computer Programming]( » [Ada Programming]( ## Objects [Variables]( and constants both store data. The difference between them is that the data stored in a variable can be changed during program execution, whereas the data stored in a constant cannot. Both must
CC BY-SA 4.0
[Computing]( » [Computer Science]( » [Computer Programming]( » [Ada Programming]( There are several forms to specify the representation of items. ## Attributes [type]( Day_Of_Month [is]( [range]( 1 .. 31; [for]( Day_Of_Month'[Size]( [use]( 8; -- 8 bits [for]( Day_Of_Month'[Alignment]( [use]( 1; -- 1
CC BY-SA 4.0
[Computing]( » [Computer Science]( » [Computer Programming]( » [Ada Programming]( Ada supports three different types of strings. Each string type is designed to solve a different problem. In addition, every string type is implemented for each available Characters type (Character, Wide_Character, Wid
CC BY-SA 4.0
[Computing]( » [Computer Science]( » [Computer Programming]( » [Ada Programming]( In Ada the subprograms are classified into two categories: procedures and functions. A procedures call is a statement and does not return any value, whereas a function returns a value and must therefore be a part of an