ada conditional assignment

  • Ada for the C++ or Java Developer
  • Statements, Declarations, and Control Structures

Statements, Declarations, and Control Structures 

Statements and declarations .

The following code samples are all equivalent, and illustrate the use of comments and working with integer variables:

Statements are terminated by semicolons in all three languages. In Ada, blocks of code are surrounded by the reserved words begin and end rather than by curly braces. We can use both multi-line and single-line comment styles in the C++ and Java code, and only single-line comments in the Ada code.

Ada requires variable declarations to be made in a specific area called the declarative part , seen here before the begin keyword. Variable declarations start with the identifier in Ada, as opposed to starting with the type as in C++ and Java (also note Ada's use of the : separator). Specifying initializers is different as well: in Ada an initialization expression can apply to multiple variables (but will be evaluated separately for each), whereas in C++ and Java each variable is initialized individually. In all three languages, if you use a function as an initializer and that function returns different values on every invocation, each variable will get initialized to a different value.

Let's move on to the imperative statements. Ada does not provide ++ or -- shorthand expressions for increment/decrement operations; it is necessary to use a full assignment statement. The := symbol is used in Ada to perform value assignment. Unlike C++'s and Java's = symbol, := can not be used as part of an expression. So, a statement like A := B := C ; doesn't make sense to an Ada compiler, and neither does a clause like if A := B then ... . Both are compile-time errors.

You can nest a block of code within an outer block if you want to create an inner scope:

It is OK to have an empty declarative part or to omit the declarative part entirely — just start the inner block with begin if you have no declarations to make. However it is not OK to have an empty sequence of statements. You must at least provide a null ; statement, which does nothing and indicates that the omission of statements is intentional.

Conditions 

The use of the if statement:

In Ada, everything that appears between the if and then keywords is the conditional expression — no parentheses required. Comparison operators are the same, except for equality ( = ) and inequality ( /= ). The English words not , and , and or replace the symbols ! , & , and | , respectively, for performing boolean operations.

It's more customary to use && and || in C++ and Java than & and | when writing boolean expressions. The difference is that && and || are short-circuit operators, which evaluate terms only as necessary, and & and | will unconditionally evaluate all terms. In Ada, and and or will evaluate all terms; and then and or else direct the compiler to employ short circuit evaluation.

Here are what switch/case statements look like:

In Ada, the case and end case lines surround the whole case statement, and each case starts with when . So, when programming in Ada, replace switch with case , and replace case with when .

Case statements in Ada require the use of discrete types (integers or enumeration types), and require all possible cases to be covered by when statements. If not all the cases are handled, or if duplicate cases exist, the program will not compile. The default case, default : in C++ and Java, can be specified using when others => in Ada.

In Ada, the break instruction is implicit and program execution will never fall through to subsequent cases. In order to combine cases, you can specify ranges using .. and enumerate disjoint values using | which neatly replaces the multiple case statements seen in the C++ and Java versions.

In Ada, loops always start with the loop reserved word and end with end loop . To leave the loop, use exit — the C++ and Java equivalent being break . This statement can specify a terminating condition using the exit when syntax. The loop opening the block can be preceded by a while or a for .

The while loop is the simplest one, and is very similar across all three languages:

Ada's for loop, however, is quite different from that in C++ and Java. It always increments or decrements a loop index within a discrete range. The loop index (or "loop parameter" in Ada parlance) is local to the scope of the loop and is implicitly incremented or decremented at each iteration of the loop statements; the program cannot directly modify its value. The type of the loop parameter is derived from the range. The range is always given in ascending order even if the loop iterates in descending order. If the starting bound is greater than the ending bound, the interval is considered to be empty and the loop contents will not be executed. To specify a loop iteration in decreasing order, use the reverse reserved word. Here are examples of loops going in both directions:

Ada uses the Integer type's ' Image attribute to convert a numerical value to a String. There is no implicit conversion between Integer and String as there is in C++ and Java. We'll have a more in-depth look at such attributes later on.

It's easy to express iteration over the contents of a container (for instance, an array, a list, or a map) in Ada and Java. For example, assuming that Int_List is defined as an array of Integer values, you can use:

  • Ada Advantages
  • ARA Community

Ada Programming/All Operators

ada conditional assignment

  • 1.1.1 Logical operators
  • 1.1.2 Relational operators
  • 1.1.3 Binary adding operators
  • 1.1.4 Unary adding operators
  • 1.1.5 Multiplying operator
  • 1.1.6 Highest precedence operator
  • 1.2 Short-circuit control forms
  • 1.3.1 Range membership test
  • 1.3.2 Subtype membership test
  • 1.3.3 Class membership test
  • 1.3.4 Range membership test
  • 1.3.5 Choice list membership test
  • 1.4.1 Wikibook
  • 1.4.2 Ada 95 Reference Manual
  • 1.4.3 Ada 2005 Reference Manual
  • 1.4.4 Ada Quality and Style Guide
  • 2.1.1 Concatenating arrays
  • 2.2.1 Concatenating strings
  • 2.3.1 Wikibook
  • 2.3.2 Ada 95 Reference Manual
  • 2.3.3 Ada 2005 Reference Manual
  • 3.1.1.1.1 Usage
  • 3.1.1.1.2 Working Example
  • 3.2.1 Wikibook
  • 3.2.2 Ada 95 Reference Manual
  • 3.2.3 Ada 2005 Reference Manual
  • 4.1.1.1.1 Usage
  • 4.1.1.1.2 Working Example
  • 4.1.2.1.1 Usage
  • 4.1.2.1.2 Working Example
  • 4.1.2.2.1 Usage
  • 4.1.2.2.2 Working Example
  • 4.2.1 Wikibook
  • 4.2.2 Ada 95 Reference Manual
  • 4.2.3 Ada 2005 Reference Manual
  • 5.1.1.1.1 Usage
  • 5.1.1.2.1 Usage
  • 5.2.1 Wikibook
  • 5.2.2 Ada 95 Reference Manual
  • 5.2.3 Ada 2005 Reference Manual
  • 6.1 Operator
  • 6.2.1 Wikibook
  • 6.2.2 Ada 95 Reference Manual
  • 6.2.3 Ada 2005 Reference Manual
  • 7.1.1.1.1 Usage
  • 7.2.1 Wikibook
  • 7.2.2 Ada Reference Manual
  • 8.1 Operator
  • 8.2.1 Wikibook
  • 8.2.2 Ada 95 Reference Manual
  • 8.2.3 Ada 2005 Reference Manual
  • 9.1.1 Wikibook
  • 9.1.2 Ada 95 Reference Manual
  • 9.1.3 Ada 2005 Reference Manual
  • 9.1.4 Ada Quality and Style Guide
  • 10.1.1 Boolean operator
  • 10.1.2 Boolean shortcut operator
  • 10.1.3 Boolean operator on arrays
  • 10.1.4 Bitwise operator
  • 10.2 Adding interfaces to tagged types
  • 10.3.1 Wikibook
  • 10.3.2.1 Ada 2005 Reference Manual
  • 10.3.3 Ada Quality and Style Guide
  • 11.1 Operator
  • 11.2.1 Wikibook
  • 11.2.2 Ada 95 Reference Manual
  • 11.2.3 Ada 2005 Reference Manual
  • 12.1 Operator
  • 12.2.1 Wikibook
  • 12.2.2 Ada 95 Reference Manual
  • 12.2.3 Ada 2005 Reference Manual
  • 13.1.1 Wikibook
  • 13.1.2 Ada 95 Reference Manual
  • 13.1.3 Ada 2005 Reference Manual
  • 13.1.4 Ada Quality and Style Guide
  • 14.1 Operator
  • 14.2.1 Wikibook
  • 14.2.2 Ada 95 Reference Manual
  • 14.2.3 Ada 2005 Reference Manual
  • 15.1 Operator
  • 15.2.1 Wikibook
  • 15.2.2 Ada 95 Reference Manual
  • 15.2.3 Ada 2005 Reference Manual
  • 16.1.1 Wikibook
  • 16.1.2 Ada 95 Reference Manual
  • 16.1.3 Ada 2005 Reference Manual
  • 16.1.4 Ada Quality and Style Guide
  • 17.1.1 Wikibook
  • 17.1.2 Ada 95 Reference Manual
  • 17.1.3 Ada 2005 Reference Manual
  • 17.1.4 Ada Quality and Style Guide
  • 18.1.1 Boolean operator
  • 18.1.2 Boolean shortcut operator
  • 18.1.3 Boolean operator on arrays
  • 18.1.4 Bitwise operator
  • 18.2.1 alternative
  • 18.2.2 delay
  • 18.3.1 Wikibook
  • 18.3.2 Ada 95 Reference Manual
  • 18.3.3 Ada 2005 Reference Manual
  • 18.3.4 Ada Quality and Style Guide
  • 19.1.1.1 Arithmetic Addition
  • 19.1.1.2.1 Usage
  • 19.1.2.1 Type Conversion
  • 19.2.1 Wikibook
  • 19.2.2 Ada 95 Reference Manual
  • 19.2.3 Ada 2005 Reference Manual
  • 20.1 Operator rem
  • 20.2.1 Wikibook
  • 20.2.2 Ada 95 Reference Manual
  • 20.2.3 Ada 2005 Reference Manual
  • 20.2.4 Ada Quality and Style Guide
  • 21.1.1 Boolean operator
  • 21.1.2 Boolean operator on arrays
  • 21.1.3 Bitwise operator
  • 21.2.1 Wikibook
  • 21.2.2 Ada 95 Reference Manual
  • 21.2.3 Ada 2005 Reference Manual
  • 21.2.4 Ada Quality and Style Guide
  • 22.1 0. PREAMBLE
  • 22.2 1. APPLICABILITY AND DEFINITIONS
  • 22.3 2. VERBATIM COPYING
  • 22.4 3. COPYING IN QUANTITY
  • 22.5 4. MODIFICATIONS
  • 22.6 5. COMBINING DOCUMENTS
  • 22.7 6. COLLECTIONS OF DOCUMENTS
  • 22.8 7. AGGREGATION WITH INDEPENDENT WORKS
  • 22.9 8. TRANSLATION
  • 22.10 9. TERMINATION
  • 22.11 10. FUTURE REVISIONS OF THIS LICENSE
  • 22.12 11. RELICENSING
  • 23 How to use this License for your documents

Standard operators

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

{\displaystyle x\land y}

Relational operators

{\displaystyle x\neq y}

Binary adding operators

{\displaystyle x+y}

Unary adding operators

{\displaystyle +x}

Multiplying operator

{\displaystyle x\times y}

Highest precedence operator

{\displaystyle x^{y}}

Short-circuit control forms

These are not operators and thus cannot be overloaded.

Membership tests

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

{\displaystyle var\in type}

Range membership test

Subtype membership test, class membership test, choice list membership test.

This language feature has been introduced in Ada 2012 .

Ada 2012 extended the membership tests to include the union (short-circuit or) of several range or value choices.

  • Ada Programming

Ada 95 Reference Manual

  • 4.5 Operators and Expression Evaluation ( Annotated )

Ada 2005 Reference Manual

Ada quality and style guide.

  • 2.1.3 Alignment of Operators
  • 5.7.4 Overloaded Operators
  • 5.7.5 Overloading the Equality Operator

Operators: &

As operator, concatenating arrays.

Any array type (including fixed Strings) can be concatenated using the & operator. You can also append a single element to an array.

Common non-standard operations

Concatenating strings.

The & operator is also defined for Bounded_String and Unbounded_String.

  • Ada Programming/Delimiters
  • Ada Programming/Operators
  • 4.4 Expressions ( Annotated )
  • 4.5.3 Binary Adding Operators ( Annotated )
  • A.4.4 Bounded-Length String Handling ( Annotated )
  • A.4.5 Unbounded-Length String Handling ( Annotated )

Operators: **

Standard operations, arithmetic power of.

The "**" operator is defined as arithmetic power of for all numeric types.

Working Example

  • 4.5.6 Highest Precedence Operators ( Annotated )

Operators: *

Arithmetic multiplication.

The "*" operator is defined as arithmetic multiplication for all numeric types.

Common Non-Standard Operations

Character replication.

A String is created where a single character is replicated n-times.

In addition to standard Strings this operator is also defined for Bounded_String and Unbounded_String.

The character replication operator is part of the Ada.Strings.Fixed package . You need to with and use the package to make the operator visible.

String replication

A String is created where a source string is replicated n-times.

In addition to standard fixed strings this operator is also defined for Bounded_String and Unbounded_String.

The string replication operator is part of the Ada.Strings.Fixed package . You need to with and use the package to make the operator visible.

  • 4.5.5 Multiplying Operators ( Annotated )
  • A.4.3 Fixed-Length String Handling ( Annotated )

Operators: -

Arithmetic subtraction.

The "-" operator is defined as arithmetic subtraction for all numeric types.

The "-" unary operator is defined as arithmetic negative sign for all numeric types.

  • Ada Programming/Mathematical calculations
  • 4.5.4 Unary Adding Operators ( Annotated )

Operators: /=

The operator /= compares two values on inequality. It is predefined for all non limited types . The operator will also be defined if a suitable operator = is available.

{\displaystyle \neq }

  • 4.5.2 Relational Operators and Membership Tests ( Annotated )

Operators: /

Standard operations, arithmetic division.

The "/" operator is defined as arithmetic division for all numeric types.

Ada Reference Manual

Operators: =.

The operator = compares two values on equality. It is predefined for all non limited types .

Operators: abs

This keyword is used for the operator that gets the absolute value of a number.

  • Ada Programming/Keywords
  • 2.9 Reserved Words ( Annotated )
  • Annex P (informative) Syntax Summary ( Annotated )
  • 3.1.3 Capitalization
  • 5.5.3 Parenthetical Expressions

Operators: and

Logical operator, boolean operator, boolean shortcut operator.

Shortcut operators are used to make the evaluation of parts of boolean expressions conditional: and then , or else . This should never be done to speed up the evaluation (with modern optimizing compilers, it will possibly not have that effect). The correct use is to prevent the evaluation of expressions known to raise an exception.

In the example above, G (Dog) is only called when the pointer Dog is not null , i.e. it actually points to something.

Actually and then and or else are not operators in the sense of the reference manual, they are called 'Short-circuit Control Forms'. The difference is that (true) operators can be redefined (i.e. overloaded), whereas these cannot. They are however defined for any boolean type.

Since Ada allows parallel evaluation of the arguments for an expression, shortcut operators are not the standard way of evaluating boolean expressions. In any case where the final result of the evaluation is guaranteed to be the same, the compiler is allowed to use a shortcut evaluation.

Boolean operator on arrays

The and operator is applied to each pair of boolean elements from the left and right arrays. The result has the same bounds as the left operand.

Bitwise operator

The operator and could be used with modular types to perform bitwise operations.

Adding interfaces to tagged types

This language feature is only available from Ada 2005 on.

  • Ada Programming/Keywords/interface
  • 3.9.4 Interface Types ( Annotated )

Operators: >=

The operator >= compares two values on greater than or equal to. It is predefined for all discrete types.

Operators: >

The operator > compares two values on being greater. It is predefined for all discrete types.

  • Ada Programming/Delimiters/<
  • Ada Programming/Delimiters/>>

Operators: in

This keyword is used in:

  • The in and in out mode of subprograms parameters.
  • membership tests
  • quantified expressions
  • 6.1 Subprogram Declarations ( Annotated )

Operators: <=

The operator <= compares two values on less than or equal to. It is predefined for all discrete types.

Operators: <

The operator < compares two values on less than. It is predefined for all discrete types.

  • Ada Programming/Delimiters/>
  • Ada Programming/Delimiters/<<

Operators: mod

This keyword is used in the mod operator and in the declaration of modular types .

Operators: not

  • Logical negation operator
  • Negative membership test : not in

Operators: or

In the below example the function G is only called when F(X) returns the value False .

This shortcut operator is sometimes used to speed up the evaluation of boolean expressions, but the Ada Style Guide recommends to compare the performance of both forms before switching one to the other. In general, it is good idea to use or else in sake of performance only when the second expression involves a function call.

The or else form is also used when the second expression is known to raise an exception unless the first expression is False .

Unlike C/C++, Ada short-cut operators are not the standard way to evaluate boolean expressions. This is because Ada is designed to do by default what is generally safer, but lets the programmer request a different behaviour.

The or operator is applied to each pair of boolean elements from the left and right arrays. The result has the same bounds as the left operand.

The operator or could be used with modular types to perform bitwise operations.

Select statement

Alternative.

See Ada Programming/Tasking#Selective waiting .

See Ada Programming/Tasking#Timeout .

  • 4.5.1 Logical Operators and Short-circuit Control Forms ( Annotated )
  • 5.5.5 Short Circuit Forms of the Logical Operators
  • 10.5.2 Short-Circuit Operators
  • 10.6.3 Bit Operations on Modular Types

Operators: +

Arithmetic addition.

The "+" operator is defined as arithmetic addition for all numeric types.

The "+" operator is defined as arithmetic plus sign for all numeric types.

Type Conversion

The operator plus sign is often used to create a type conversion operator:

Operators: rem

Operator rem.

The rem keyword is used as the remainder operator, that is, the remainder of the signed integer division. The following formula applies:

Operators: xor

The xor operation is applied to each boolean inside the array .

The operator xor could be used with modular types and also with boolean arrays to perform bitwise operations.

GNU Free Documentation License

Version 1.3, 3 November 2008 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc. < http://fsf.org/ >

Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

0. PREAMBLE

The purpose of this License is to make a manual, textbook, or other functional and useful document "free" in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others.

This License is a kind of "copyleft", which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software.

We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference.

1. APPLICABILITY AND DEFINITIONS

This License applies to any manual or other work, in any medium, that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. Such a notice grants a world-wide, royalty-free license, unlimited in duration, to use that work under the conditions stated herein. The "Document", below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as "you". You accept the license if you copy, modify or distribute the work in a way requiring permission under copyright law.

A "Modified Version" of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language.

A "Secondary Section" is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (Thus, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them.

The "Invariant Sections" are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License. If a section does not fit the above definition of Secondary then it is not allowed to be designated as Invariant. The Document may contain zero Invariant Sections. If the Document does not identify any Invariant Sections then there are none.

The "Cover Texts" are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text may be at most 25 words.

A "Transparent" copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, that is suitable for revising the document straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup, or absence of markup, has been arranged to thwart or discourage subsequent modification by readers is not Transparent. An image format is not Transparent if used for any substantial amount of text. A copy that is not "Transparent" is called "Opaque".

Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML, PostScript or PDF designed for human modification. Examples of transparent image formats include PNG, XCF and JPG. Opaque formats include proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML, PostScript or PDF produced by some word processors for output purposes only.

The "Title Page" means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, "Title Page" means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text.

The "publisher" means any person or entity that distributes copies of the Document to the public.

A section "Entitled XYZ" means a named subunit of the Document whose title either is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (Here XYZ stands for a specific section name mentioned below, such as "Acknowledgements", "Dedications", "Endorsements", or "History".) To "Preserve the Title" of such a section when you modify the Document means that it remains a section "Entitled XYZ" according to this definition.

The Document may include Warranty Disclaimers next to the notice which states that this License applies to the Document. These Warranty Disclaimers are considered to be included by reference in this License, but only as regards disclaiming warranties: any other implication that these Warranty Disclaimers may have is void and has no effect on the meaning of this License.

2. VERBATIM COPYING

You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3.

You may also lend copies, under the same conditions stated above, and you may publicly display copies.

3. COPYING IN QUANTITY

If you publish printed copies (or copies in media that commonly have printed covers) of the Document, numbering more than 100, and the Document's license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects.

If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages.

If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a computer-network location from which the general network-using public has access to download using public-standard network protocols a complete Transparent copy of the Document, free of added material. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public.

It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document.

4. MODIFICATIONS

You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version:

  • Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission.
  • List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has fewer than five), unless they release you from this requirement.
  • State on the Title page the name of the publisher of the Modified Version, as the publisher.
  • Preserve all the copyright notices of the Document.
  • Add an appropriate copyright notice for your modifications adjacent to the other copyright notices.
  • Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below.
  • Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice.
  • Include an unaltered copy of this License.
  • Preserve the section Entitled "History", Preserve its Title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified Version as given on the Title Page. If there is no section Entitled "History" in the Document, create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence.
  • Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the "History" section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission.
  • For any section Entitled "Acknowledgements" or "Dedications", Preserve the Title of the section, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein.
  • Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles.
  • Delete any section Entitled "Endorsements". Such a section may not be included in the Modified version.
  • Do not retitle any existing section to be Entitled "Endorsements" or to conflict in title with any Invariant Section.
  • Preserve any Warranty Disclaimers.

If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles.

You may add a section Entitled "Endorsements", provided it contains nothing but endorsements of your Modified Version by various parties—for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard.

You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one.

The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version.

5. COMBINING DOCUMENTS

You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice, and that you preserve all their Warranty Disclaimers.

The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work.

In the combination, you must combine any sections Entitled "History" in the various original documents, forming one section Entitled "History"; likewise combine any sections Entitled "Acknowledgements", and any sections Entitled "Dedications". You must delete all sections Entitled "Endorsements".

6. COLLECTIONS OF DOCUMENTS

You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects.

You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document.

7. AGGREGATION WITH INDEPENDENT WORKS

A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, is called an "aggregate" if the copyright resulting from the compilation is not used to limit the legal rights of the compilation's users beyond what the individual works permit. When the Document is included in an aggregate, this License does not apply to the other works in the aggregate which are not themselves derivative works of the Document.

If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one half of the entire aggregate, the Document's Cover Texts may be placed on covers that bracket the Document within the aggregate, or the electronic equivalent of covers if the Document is in electronic form. Otherwise they must appear on printed covers that bracket the whole aggregate.

8. TRANSLATION

Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License, and all the license notices in the Document, and any Warranty Disclaimers, provided that you also include the original English version of this License and the original versions of those notices and disclaimers. In case of a disagreement between the translation and the original version of this License or a notice or disclaimer, the original version will prevail.

If a section in the Document is Entitled "Acknowledgements", "Dedications", or "History", the requirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title.

9. TERMINATION

You may not copy, modify, sublicense, or distribute the Document except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, or distribute it is void, and will automatically terminate your rights under this License.

However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.

Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.

Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, receipt of a copy of some or all of the same material does not give you any rights to use it.

10. FUTURE REVISIONS OF THIS LICENSE

The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See http://www.gnu.org/copyleft/ .

Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License "or any later version" applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation. If the Document specifies that a proxy can decide which future versions of this License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Document.

11. RELICENSING

"Massive Multiauthor Collaboration Site" (or "MMC Site") means any World Wide Web server that publishes copyrightable works and also provides prominent facilities for anybody to edit those works. A public wiki that anybody can edit is an example of such a server. A "Massive Multiauthor Collaboration" (or "MMC") contained in the site means any set of copyrightable works thus published on the MMC site.

"CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0 license published by Creative Commons Corporation, a not-for-profit corporation with a principal place of business in San Francisco, California, as well as future copyleft versions of that license published by that same organization.

"Incorporate" means to publish or republish a Document, in whole or in part, as part of another Document.

An MMC is "eligible for relicensing" if it is licensed under this License, and if all works that were first published under this License somewhere other than this MMC, and subsequently incorporated in whole or in part into the MMC, (1) had no cover texts or invariant sections, and (2) were thus incorporated prior to November 1, 2008.

The operator of an MMC Site may republish an MMC contained in the site under CC-BY-SA on the same site at any time before August 1, 2009, provided the MMC is eligible for relicensing.

How to use this License for your documents

To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page:

If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace the "with...Texts." line with this:

If you have Invariant Sections without Cover Texts, or some other combination of the three, merge those two alternatives to suit the situation.

If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software.

ada conditional assignment

  • Book:Ada Programming/Ada 2012 feature
  • Book:Ada Programming/Ada 2005 feature
  • Book:Ada Programming
  • Book:Ada Programming/Print version
  • Book:Ada Programming/Pages containing deprecated templates

Navigation menu

Ada Home June 16, 1997

Ada Can Do It!

© by Samuel Mize, Team Ada copyright notice at end of text [email protected]

Common false claims about things Ada won't let you do, and how to do them (and why some are not directly supported)

We sometimes hear "You can't do X in Ada."

In fact, you can do X in Ada, C, Fortran, etc. It may be easy or difficult, it may require more or less programmer work, but they can all compute the same results.

What the complainer means is that "Ada does not support doing X easily."

In some cases this is intentional. In some case it is fixed by the upgrade from Ada 83 to Ada 95. In many cases it is simply false.

Where a capability was intentionally left out, other ways are provided to accomplish the task.

As a rule, Ada avoids easy-but-dangerous approaches, preferring safer approaches that require more programmer effort. Ada also tends toward including a lot of information that makes code easier to read, and makes errors easier to detect, even if that makes the code harder to write.

Here are some common can't-do claims, and how to do them in Ada:

Two appendices containing extended example code are linked after the descriptions.

1. Loose typing

Ada can be as "quick and dirty" as C if one uses only the predefined types (character, string, integer, float), ignoring Ada's strong typing. (Just because you CAN define a new type for each variable, that doesn't mean that you HAVE to, or that you SHOULD!)

Experience and training are important with Ada. Naive programmers may over-specify types and create a lot of programmer work with little benefit.

On the other hand, getting significant code actually WORKING can be much faster with Ada, since Ada catches a lot of simple mistakes. This is especially true for "rapid prototyping," since such a prototype is, by definition, not being carefully designed and coded.

Lisp and its derivatives provide data items ("atoms") that can be treated as string, character, integer, float or whatever. This is often promoted for rapid prototyping. Such a data type can be built in Ada, with a variant record or a tagged type; once this has been done, the type exists to support other prototyping efforts. Several such types have been defined for local projects. However, most Ada vendors have targeted the high-efficiency area, rather than rapid prototyping.

2. C-style "union" types

These are used for different reasons, each with a different solution in Ada.

If you just want a record type with varying fields, based on a "key" field, use a variant record.

If you want to define a base type, then extend it with new fields, but still pass it to the base type's subprograms, use an Ada 95 tagged type. In Ada 83, see the following.

If you must be able to manually alter the "key" field -- if, for instance, you are interfacing to a C subsystem that uses "union" types -- you can overlay several variables, each of a type representing one of the "union" alternatives.

Or, you could define the data item as a packed array of bytes (or bits) and access fields via unchecked_conversion. If you are defining a "union" type that will be used frequently, you can provide access functions and procedures that automatically select the right sub-array and convert it. After inlining and optimization, these should come close to the efficiency of a record field access. This is a "heavy" solution compared to C, but encapsulates a lot of valuable information for later programmers and for the optimizing passes of the compiler.

3. Memory overlays

On any machine where memory overlays make sense, Ada compilers support them, and always have. This was compiler-dependent in Ada 83, and is better standardized in Ada 95.

However, since there are machines for which a memory overlay is meaningless (like the Symbolics Lisp Machine), the standard does not require that a compiler support them. Some people have been confused by this. The Ada standard does not require overlay support, but it does not require absence of overlay support.

The Ada 83 standard says that putting one item at the same address as another is "erroneous." This doesn't mean that it's a mistake. It's a formal term that means the program's behavior is outside the scope of the standard. It could work as expected, it could silently fail, it could cause the Earth to crash into the Sun. The standard is silent. (In the real world, almost all compilers have supported overlays, and almost none crash the Earth into the Sun.)

In Ada 95, the mechanism for overlays is more standardized. If you specify that a variable is "volatile" and "aliased" it should reside in memory and provide a valid address; you can put another "volatile" item at that address, on any architecture where memory overlays make sense. You should check with your vendor to determine exactly what your compiler requires.

Overlays should often be replaced with use of Unchecked_Conversion. Some people avoid this, to avoid procedure-call overhead and copying the data. Whether this actually happens depends on the exact code and the compiler's optimizations. If your resources are tightly constrained, you should check with your vendor and/or test the compiler's output to determine the most efficient way to use a particular compiler.

If overlays are a requirement for your application, you need to choose your compiler carefully. In practice, Ada compilers have always supported this on architectures where it made sense.

4. Address arithmetic

The most common use of pointer arithmetic is to simulate variable-length arrays, which are directly supported in Ada 83 and Ada 95.

Ada 95 directly supports pointer arithmetic. You instantiate a predefined package to use it. Ada 83 support for this is compiler-dependent.

Some C programmers use pointer arithmetic to manipulate array elements because they feel it is faster than using array subscripts. With modern compilers, this is generally false, even in C. Optimization of array accesses is a well-defined compiler technology, and a compiler is much more thorough about it than a human programmer.

5. Bit manipulations

In Ada 83, this required use of packed bit arrays and unchecked conversion between the array type and integer. (This still works, and works for items other than integers.)

Integer bit manipulation is supported directly in Ada 95, with "modular" integer types.

6. Conditional compilation

Ada's design philosophy is that the code you see is the code that runs.

A lot of debugging and maintenance effort has been wasted through mistakes about whether or not given source code was used in the last compilation.

For major code replacements, like platform-specific interface code, it is better to isolate the varying code into a package, and have different bodies for that package. One approach to this is to have several platform-specific packages with different names (e.g., Dos_Services, Unix_Services) and use a library-level renaming declaration to select the appropriate package:

For small replacements, like debug/print statements, you can embed them in normal "if" statements. The efficiency loss is usually indetectable. Some compilers will remove "dead" code, so with "if" statements based on static values, there may be no efficiency loss at all.

In the very few cases where a preprocessor is the best engineering choice for managing code changes, it can be used to generate a read-only source file for compilation from a conditionally-encoded source file. You must take care to make changes only in the conditionally-encoded file. Some vendors automate this. For example, the Rational Apex compiler generates read-only Ada files from preprocessor input files. When a preprocessor file changes, it regenerates and recompiles the Ada file.

7. Macros and templates (see also "conditional compilation")

Ada provides ways to do the tasks commonly approached with preprocessor macros and templates.

The Ada generic provides a more structured way to define reusable code structures that work for many variables, subprograms or types. It is a type-safe "template" facility.

One common use of macros in C is to avoid procedure-call overhead. For this, Ada encourages optimizing compilation and procedure inlining.

In C, three "legitimate" uses of macros are for defining compile-time constants, types, and inline procedures. Ada has all three of these facilities, without macros.

For generating different versions of a unit -- for example, for platform-specific code in a run-time system -- the Ada approach is to create a package that encapsulates the platform-specific features, and have different platform-specific bodies for that unit.

General text-substitution macros, like those in the C preprocessor, are considered unsafe. For example, a macro can refer to a variable X; depending where the macro is expanded X may be one thing, or another, or may not even be visible. Also, debugging is harder when the code compiled is a complex function of the code text.

8. Functions that can change their parameters

This was intentionally excluded, but the same effect can be had in Ada 95 with access parameters. Note that this exactly mirrors the C approach, where you pass the address of a variable to modify it.

9. Assignment and increment operators (like += and ++ in C)

Ada provides these computations, of course, but not as special operators.

Their exclusion is a judgement call. In some cases, they can make individual statements simpler to read. Overall, most code is clearer and more reliable without them. It's easy to misread "x += expression" as "x := expression" instead of "x = x + expression", especially if this line is buried in a sequence of assignments with varying assignment operators.

Further, typos are less likely to result in valid (but erroneous) code. Note that "+" and "=" are on the same key on most keyboards, and "-" is next to it. "+=" and "-=" are easy fumbles for "=", or for each other.

John Volan has proposed a generic package that provides such procedures as Increment, Decrement, and Multiply for a given integer type. See the code in appendix A1 .

10. Value-returning assignment

This was intentionally excluded. You have to code around it. Doing so is generally simple, and makes the code clearer for maintenance. Assignments buried in expressions are a significant source of bugs and maintenance errors in C.

11. "static" variables

Variables in Ada are lexically scoped; that is, they are created and destroyed according to their location in the program text.

A "static" variable in a C file, outside any function, exists from program startup to termination. To get this in Ada, declare the variable (or constant) in a library package. Items declared in the package's specification persist, and are visible in other units that "with" that package. (If declared in the "private" section, they are only visible in the private part of "child" units of this package.) Those declared in the package's body are only visible inside the package.

A "static" variable inside a C function is permanent, but is only visible inside the function. Many Ada programmers simply co-locate data items and their subprograms:

To limit the scope of a variable to one subprogram is a little more work. One approach is to put the subprogram inside a local package:

For a single variable in a single subprogram, this is more code than C requires. However:

12. Direct multiple inheritance in object-oriented programming

There are several common kinds of multiple inheritance, each with several variants. Instead of picking one and building it into Ada's syntax, the Ada 95 developers provided building blocks that can be used to build up the different types of multiple inheritance. The Ada 95 Rationale (section 4.6) describes how to do this.

13. Variable-length argument lists

Most procedural languages (e.g., C, Fortran, Ada) provide for only fixed parameter lists. However, there are workarounds in all of these languages. Fortran has a "varargs" facility; C has "varargs" and "stdarg" (which is ANSI C compatible).

The Ada community has not yet adopted a standard variable-length parameter mechanism. However, it is easy to do in several ways, each of which is best for some applications. The wise programmer, when coding one of them, will create a var-arg package that can be reused.

The Ada approaches take more programmer work than, for example, the C approach, which directly accesses the call stack. This is partly because Ada's semantics don't define a call stack. The Ada approaches will work even on machines (like "Lisp machines") where the "call stack" may not be a single chunk of memory.

The Ada approaches are also type-safe: the called subprogram knows definitely what type of object the caller provided. (In the last approach shown, the called subprogram doesn't know the parameter's type, but it dynamically dispatches to the correct subprogram for the parameter.)

Several approaches are shown in appendix A2 , specifically:

14. Rapid prototyping

There are three common types of rapid prototype: a GUI prototype, an exploratory or "proof of concept" prototype, and a small-scale prototype intended to verify a design for a larger system.

For a GUI prototype, the appropriate tool is not a language at all, but a GUI builder.

A "proof of concept" prototype typically uses a GUI builder for a user interface, and a programming language to "rough in" a limited subset of the proposed functionality. Ada is getting more representation among such tools. Some people prefer C for this, some prefer Lisp, some prefer Ada. Experience suggests that the fastest prototype comes from the language most familiar to the developer. Some argue against Ada for this application because of its strong typing; see "Loose typing". Ada's type support can be useful for prototyping, for example with attributes like 'Image.

Design prototypes are often useful, and generally should be built using the language and environment to be used for the real system, so experience with the prototype will directly apply to the actual system. Some people advocate building a prototype in a special prototyping environment, then using that prototype as a first-level design for the real system. There are few, if any, real-world success stories available for this approach.

Copyright © 1997 Samuel Mize. Permission granted to copy the entire text including this notice, to quote entire sections with attribution, and to use code from (or derived from) the examples herein without limit.

What did you think of this article?

Page last modified: 1997-06-16

Programming-Idioms

  • C++
  • Or search :

Idiom #252 Conditional assignment

Assign to the variable x the string value "a" if calling the function condition returns true , or the value "b" otherwise.

  • View revisions
  • Successive conditions
  • for else loop
  • Report a bug

Please choose a nickname before doing this

No security, no password. Other people might choose the same nickname.

19th Edition of Global Conference on Catalysis, Chemical Engineering & Technology

  • Victor Mukhin

Victor Mukhin, Speaker at Chemical Engineering Conferences

Victor M. Mukhin was born in 1946 in the town of Orsk, Russia. In 1970 he graduated the Technological Institute in Leningrad. Victor M. Mukhin was directed to work to the scientific-industrial organization "Neorganika" (Elektrostal, Moscow region) where he is working during 47 years, at present as the head of the laboratory of carbon sorbents.     Victor M. Mukhin defended a Ph. D. thesis and a doctoral thesis at the Mendeleev University of Chemical Technology of Russia (in 1979 and 1997 accordingly). Professor of Mendeleev University of Chemical Technology of Russia. Scientific interests: production, investigation and application of active carbons, technological and ecological carbon-adsorptive processes, environmental protection, production of ecologically clean food.   

Title : Active carbons as nanoporous materials for solving of environmental problems

Quick links.

  • Conference Brochure
  • Tentative Program

Watsapp

5.2 Assignment Statements

This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue

[An assignment_statement replaces the current value of a variable with the result of evaluating an expression .]

assignment _ statement ::= variable _ name := expression ;

The execution of an assignment_statement includes the evaluation of the expression and the assignment of the value of the expression into the target . [An assignment operation (as opposed to an assignment _ statement ) is performed in other contexts as well, including object initialization and by-copy parameter passing.] The target of an assignment operation is the view of the object to which a value is being assigned; the target of an assignment _ statement is the variable denoted by the variable _ name .

Don't confuse this notion of the “target” of an assignment with the notion of the “target object” of an entry call or requeue.

Don't confuse the term “assignment operation” with the assignment_statement . The assignment operation is just one part of the execution of an assignment_statement . The assignment operation is also a part of the execution of various other constructs; see 7.6.1 , “ Completion and Finalization ” for a complete list. Note that when we say, “such-and-such is assigned to so-and-so”, we mean that the assignment operation is being applied, and that so-and-so is the target of the assignment operation.

Name Resolution Rules ​

The variable _ name of an assignment_statement is expected to be of any type. The expected type for the expression is the type of the target.

An assignment_statement as a whole is a “complete context”, so if the variable _ name of an assignment_statement is overloaded, the expression can be used to help disambiguate it. For example:

type P1 is access R1; type P2 is access R2; 4.c function F return P1; function F return P2; 4.d X : R1; begin F.all := X; -- Right hand side helps resolve left hand side

Legality Rules ​

The target [denoted by the variable _ name ] shall be a variable of a nonlimited type.

If the target is of a tagged class-wide type T 'Class, then the expression shall either be dynamically tagged, or of type T and tag-indeterminate (see 3.9.2 ).

This is consistent with the general rule that a single dispatching operation shall not have both dynamically tagged and statically tagged operands. Note that for an object initialization (as opposed to the assignment_statement ), a statically tagged initialization expression is permitted, since there is no chance for confusion (or Tag _ Check failure). Also, in an object initialization, tag-indeterminate expressions of any type covered by T 'Class would be allowed, but with an assignment_statement , that might not work if the tag of the target was for a type that didn't have one of the dispatching operations in the tag-indeterminate expression.

Dynamic Semantics ​

For the execution of an assignment_statement , the variable _ name and the expression are first evaluated in an arbitrary order.

Other rules of the language may require that the bounds of the variable be determined prior to evaluating the expression , but that does not necessarily require evaluation of the variable _ name , as pointed out by the ACID.

When the type of the target is class-wide:

  • If the expression is tag-indeterminate (see 3.9.2 ), then the controlling tag value for the expression is the tag of the target;

See 3.9.2 , “ Dispatching Operations of Tagged Types ”.

  • Otherwise [(the expression is dynamically tagged)], a check is made that the tag of the value of the expression is the same as that of the target; if this check fails, Constraint _ Error is raised.

The value of the expression is converted to the subtype of the target. [The conversion can raise an exception (see 4.6 ).]

4.6 , “ Type Conversions ” defines what actions and checks are associated with subtype conversion. For non-array subtypes, it is just a constraint check presuming the types match. For array subtypes, it checks the lengths and slides if the target is constrained. “Sliding” means the array doesn't have to have the same bounds, so long as it is the same length.

In cases involving controlled types, the target is finalized, and an anonymous object can be used as an intermediate in the assignment, as described in 7.6.1 , “ Completion and Finalization ”. In any case, the converted value of the expression is then assigned to the target, which consists of the following two steps:

To be honest: 7.6.1 actually says that finalization happens always, but unless controlled types are involved, this finalization during an assignment_statement does nothing.

  • The value of the target becomes the converted value.
  • If any part of the target is controlled, its value is adjusted as explained in 7.6 .

If any parts of the object are controlled, abort is deferred during the assignment operation itself, but not during the rest of the execution of an assignment_statement .

NOTE The tag of an object never changes; in particular, an assignment_statement does not change the tag of the target.

The implicit subtype conversion described above for assignment_statement s is performed only for the value of the right-hand side expression as a whole; it is not performed for subcomponents of the value.

The determination of the type of the variable of an assignment_statement may require consideration of the expression if the variable name can be interpreted as the name of a variable designated by the access value returned by a function call, and similarly, as a component or slice of such a variable (see 8.6 , “ The Context of Overload Resolution ”).

Examples of assignment statements:

Value := Max _ Value - 1; Shade := Blue; 19 Next _ Frame(F)(M, N) := 2.5; -- see 4.1.1 U := Dot _ Product(V, W); -- see 6.3 20/4

Writer := (Status = > Open, Unit = > Printer, Line _ Count = > 60); -- see 3.8.1 Next.all := (72074, null, Head); -- see 3.10.1

Examples involving scalar subtype conversions:

I, J : Integer range 1 .. 10 := 5; K : Integer range 1 .. 20 := 15; ... 23 I := J; -- identical ranges K := J; -- compatible ranges J := K; -- will raise Constraint _ Error if K > 10

Examples involving array subtype conversions:

A : String(1 .. 31); B : String(3 .. 33); ... 26 A := B; -- same number of components 27 A(1 .. 9) := "tar sauce"; A(4 .. 12) := A(1 .. 9); -- A(1 .. 12) = "tartar sauce"

Assignment_statement s are well-defined even in the case of overlapping slices of the same array, because the variable _ name and expression are both evaluated before copying the value into the variable. In the above example, an implementation yielding A(1 .. 12) = "tartartartar" would be incorrect.

Extensions to Ada 83 ​

We now allow user-defined finalization and value adjustment actions as part of assignment_statement s (see 7.6 , “ Assignment and Finalization ”).

Wording Changes from Ada 83 ​

The special case of array assignment is subsumed by the concept of a subtype conversion, which is applied for all kinds of types, not just arrays. For arrays it provides “sliding”. For numeric types it provides conversion of a value of a universal type to the specific type of the target. For other types, it generally has no run-time effect, other than a constraint check.

We now cover in a general way in 3.7.2 the erroneous execution possible due to changing the value of a discriminant when the variable in an assignment_statement is a subcomponent that depends on discriminants.

Incompatibilities With Ada 95 ​

The change of the limited check from a resolution rule to a legality rule is not quite upward compatible. For example

type AccNonLim is access NonLim; function Foo (Arg : in Integer) return AccNonLim; type AccLim is access Lim; function Foo (Arg : in Integer) return AccLim; Foo(2).all := Foo(1).all;

where NonLim is a nonlimited type and Lim is a limited type. The assignment is legal in Ada 95 (only the first Foo would be considered), and is ambiguous in Ada 2005. We made the change because we want limited types to be as similar to nonlimited types as possible. Limited expressions are now allowed in all other contexts (with a similar incompatibility), and it would be odd if assignments had different resolution rules (which would eliminate ambiguities in some cases). Moreover, examples like this one are rare, as they depend on assigning into overloaded function calls.

5.2.1 Target Name Symbols ​

@, known as the target name of an assignment statement, provides an abbreviation to avoid repetition of potentially long names in assignment statements.

target _ name ::= @

[If a target_name occurs in an assignment_statement A , the variable _ name V of A is a complete context. The target name is a constant view of V , having the nominal subtype of V .]

The complete context rule is formally given in 8.6 . The constant view rule is formally given in 3.3 ; the nominal subtype is a property taken from the target object as described below in Dynamic Semantics.

A target_name shall appear only in the expression of an assignment_statement .

For the execution of an assignment_statement with one or more target_name s appearing in its expression , the variable _ name V of the assignment_statement is evaluated first to determine the object denoted by V , and then the expression of the assignment_statement is evaluated with the evaluation of each target_name yielding a constant view of the target whose properties are otherwise identical to those of the view provided by V . The remainder of the execution of the assignment_statement is as given in 5.2 .

To be honest: The properties here include static properties like whether the target_name is aliased and the nominal subtype of the target_name . It was too weird to give separate rules for static and dynamic properties that said almost the same thing.

Use of a target_name can be erroneous if the variable _ name V is a discriminant-dependent component, and some other constituent of the expression modifies the discriminant governing the component V . The assignment probably would be erroneous anyway, but the use of a target_name eliminates the possibility that a later evaluation of V raises an exception before any erroneous execution occurs. See 3.7.2 .

Examples of the use of target name symbols:

Board(1, 1) := @ + 1.0; -- An abbreviation for Board(1, 1) := Board(1, 1) + 1.0; -- (Board is declared in 3.6.1 ). 8/5

My _ Complex _ Array : array (1 .. Max) of Complex; -- See 3.3.2 , 3.8 . ... -- Square the element in the Count (see 3.3.1 ) position: My _ Complex _ Array (Count) := (Re = > @.Re * * 2 - @.Im * * 2, Im = > 2.0 * @.Re * @.Im); -- A target _ name can be used multiple times and -- as a prefix if desired.

Extensions to Ada 2012 ​

The target name symbol @ is new.

  • 5.2.1 Target Name Symbols

COMMENTS

  1. 3.2 If expressions

    If the conditional expression is the argument of a type conversion then effectively the conversion is considered pushed down to the dependent expressions. Thus. X := Float ( if P then A else B); is equivalent to. X := ( if P then Float (A) else Float (B)); As a consequence we can write. X := Float ( if P then 27 else 0.3);

  2. How to have multiple conditionals in an if statement in Ada

    velocity = user value. temperature = user value //ignore those list numbers. I have set in my (.ads) file that each of these ranges has a criticle value. I want to create an if statement that has multiple conditionals. in pseudo : If velocity = critical velocity & temperature = critical temperature & altitude = critical altitude then print ...

  3. Why are if expressions and if statements in ada, also for case

    4. Taken from Introduction to Ada—If expressions: Ada's if expressions are similar to if statements. However, there are a few differences that stem from the fact that it is an expression: All branches' expressions must be of the same type. It must be surrounded by parentheses if the surrounding expression does not already contain them.

  4. Statements, Declarations, and Control Structures

    In Ada, the case and end case lines surround the whole case statement, and each case starts with when.So, when programming in Ada, replace switch with case, and replace case with when.. Case statements in Ada require the use of discrete types (integers or enumeration types), and require all possible cases to be covered by when statements. If not all the cases are handled, or if duplicate cases ...

  5. Ada Programming/Expressions

    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;

  6. If Statements

    For the execution of an if_statement, the condition specified after if, and any condition s specified after elsif, are evaluated in succession (treating a final else as elsif True then), until one evaluates to True or all condition s are evaluated and yield False. If a condition evaluates to True, then the corresponding sequence_of_statements is executed; otherwise none of them is executed.

  7. 5.3 If Statements

    Wording Changes from Ada 2005 9.a/3. Moved definition of condition to 4.5.7 in order to eliminate a forward reference. Previous. 5.2 Assignment Statements. Next. 5.4 Case Statements. Learning. Tutorial; Books; Learn Ada (by AdaCore) Learn SPARK (by AdaCore) Docs. Reference Manual; Style Guide; Code Search; Community. Forum;

  8. Ada Programming/All Operators

    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 ...

  9. 1.3.2 Overview: Expressions

    1.3.2 Overview: Expressions. Those whose first language was Algol 60 or Algol 68 or who have had the misfortune to dabble in horrid languages such as C will have been surprised that a language of the richness of Ada does not have conditional expressions. Well, the good news is that Ada 2012 has at last introduced conditional expressions which ...

  10. 4.5.7 Conditional Expressions

    Conditional Expressions. 1/3. A conditional_expression selects for evaluation at most one of the enclosed dependent_ expression s, depending on a decision among the alternatives. One kind of conditional_expression is the if_expression, which selects for evaluation a dependent_ expression depending on the value of one or more corresponding ...

  11. 9.7 Select Statements

    A procedure call can be used as the entry_call_alternative in a timed or conditional entry call, if the procedure might actually be an entry. Since the fact that something is an entry could be used in resolving these calls in Ada 95, it is possible for timed or conditional entry calls that resolved in Ada 95 to be ambiguous in Ada 2005.

  12. Syntax Cheat Sheet

    Function. function Fibonacci(X: Natural) return Natural is if X = 0 or X = 1 then return X; else return Fibonacci(X - 1) + Fibonacci(X - 2); end if; end Fibonacci; Subprogram call (no parameters) A; Subprogram call with named Parameters. Foo(Bar1 => Value, Baz => Value2) Override specifier.

  13. Ternary conditional operator

    Ada. The 2012 edition of Ada has introduced conditional expressions ... in this case we can use a conditional assignment expression, or a function call. Bear in mind also that some types allow initialization, but do not allow assignment, or even that the assignment operator and the constructor do totally different things. This last is true for ...

  14. Ada Home 1997-06 -- Article: Ada Can Do It!

    Conditional compilation. Ada's design philosophy is that the code you see is the code that runs. ... especially if this line is buried in a sequence of assignments with varying assignment operators. Further, typos are less likely to result in valid (but erroneous) code. Note that "+" and "=" are on the same key on most keyboards, and "-" is ...

  15. Conditional variable assignment? : r/ada

    Pointers to news, articles, and other items of interest about the Ada programming language.

  16. Conditional assignment, in Ada

    Idiom #252 Conditional assignment. Assign to the variable x the string value "a" if calling the function condition returns true, or the value "b" otherwise. Ada.

  17. 4.5 Operators and Expression Evaluation

    3. function "and"(Left, Right : T) return T function "or" (Left, Right : T) return T function "xor"(Left, Right : T) return T. 4. For boolean types, the predefined logical operators and, or, and xor perform the conventional operations of conjunction, inclusive disjunction, and exclusive disjunction, respectively. 5.

  18. PDF IS HIRING AN: Accountant

    Depending on assignment, the duties of the Accountant position include, but are not limited to, responding, and ... Conditional Offer of Employment An offer of employment will be conditioned upon legal ability to work in the ... Westlands Water District is an Equal Opportunity/ADA Employer BENEFIT PACKAGE INCLUDES:

  19. "Metallurgical Plant "Electrostal" JSC

    Round table 2021. "Electrostal" Metallurgical plant" JSC has a number of remarkable time-tested traditions. One of them is holding an annual meeting with customers and partners in an extеnded format in order to build development pathways together, resolve pressing tasks and better understand each other. Although the digital age ...

  20. 40 Facts About Elektrostal

    40 Facts About Elektrostal. Elektrostal is a vibrant city located in the Moscow Oblast region of Russia. With a rich history, stunning architecture, and a thriving community, Elektrostal is a city that has much to offer. Whether you are a history buff, nature enthusiast, or simply curious about different cultures, Elektrostal is sure to ...

  21. 5.6 Statements

    Loops with many scattered exit statements can indicate fuzzy thinking regarding the loop's purpose in the algorithm. Such an algorithm might be coded better some other way, for example, with a series of loops. Some rework can often reduce the number of exit statements and make the code clearer.. See also Guidelines 5.1.3 and 5.6.4.

  22. Victor Mukhin

    Catalysis Conference is a networking event covering all topics in catalysis, chemistry, chemical engineering and technology during October 19-21, 2017 in Las Vegas, USA. Well noted as well attended meeting among all other annual catalysis conferences 2018, chemical engineering conferences 2018 and chemistry webinars.

  23. Elektrostal

    In 1938, it was granted town status. [citation needed]Administrative and municipal status. Within the framework of administrative divisions, it is incorporated as Elektrostal City Under Oblast Jurisdiction—an administrative unit with the status equal to that of the districts. As a municipal division, Elektrostal City Under Oblast Jurisdiction is incorporated as Elektrostal Urban Okrug.

  24. 5.2 Assignment Statements

    Syntax. 2. assignment_statement ::=. variable_ name := expression; 3. The execution of an assignment_statement includes the evaluation of the expression and the assignment of the value of the expression into the target. [An assignment operation (as opposed to an assignment _ statement) is performed in other contexts as well, including object ...