Programming in Ada 2012 with a Preview of Ada 2022 2nd Edition John Barnes all chapter instant download
Programming in Ada 2012 with a Preview of Ada 2022 2nd Edition John Barnes all chapter instant download
https://ebookmass.com
https://ebookmass.com/product/programming-in-
ada-2012-with-a-preview-of-ada-2022-2nd-edition-
john-barnes/
https://ebookmass.com/product/murder-most-festive-ada-moncrieff-2/
testbankdeal.com
https://ebookmass.com/product/murder-most-festive-ada-moncrieff-3/
testbankdeal.com
https://ebookmass.com/product/murder-most-festive-ada-moncrieff/
testbankdeal.com
https://ebookmass.com/product/the-ada-practical-guide-to-dental-
implants-1st-edition-luigi-o-massa/
testbankdeal.com
The Stoics on Lekta: All there is to Say Ada Bronowski
https://ebookmass.com/product/the-stoics-on-lekta-all-there-is-to-say-
ada-bronowski/
testbankdeal.com
https://ebookmass.com/product/learning-scientific-programming-with-
python-2nd-edition-christian-hill-2/
testbankdeal.com
https://ebookmass.com/product/learning-scientific-programming-with-
python-2nd-edition-christian-hill/
testbankdeal.com
https://ebookmass.com/product/game-programming-with-unity-and-c-a-
complete-beginners-guide-2nd-edition-casey-hardman/
testbankdeal.com
314–321, 3rd Floor, Plot 3, Splendor Forum, Jasola District Centre, New Delhi – 110025, India
103 Penang Road, #05–06/07, Visioncrest Commercial, Singapore 238467
www.cambridge.org
Information on this title: www.cambridge.org/9781009181341
DOI: 10.1017/9781009181358
Foreword xv
Preface xvii
Part 1 An Overview 1
1 Introduction 3
1.1 Standard development 3
1.2 Software engineering 4
1.3 Evolution and abstraction 6
1.4 Structure and objectives of this book 8
1.5 References 10
2 Simple Concepts 11
2.1 Key goals 11
2.2 Overall structure 12
2.3 The scalar type model 17
2.4 Arrays and records 19
2.5 Access types 22
2.6 Errors and exceptions 23
2.7 Terminology 26
3 Abstraction 27
3.1 Packages and private types 27
3.2 Objects and inheritance 30
3.3 Classes and polymorphism 34
3.4 Genericity 40
3.5 Object oriented terminology 41
3.6 Tasking 43
4 Programs and Libraries 47
4.1 The hierarchical library 47
4.2 Input–output 49
vii
19 Generics 469
19.1 Declarations and instantiations 469
19.2 Type parameters 475
19.3 Subprogram parameters 485
19.4 Package parameters 492
19.5 Generic library units 498
20 Tasking 501
20.1 Parallelism 501
20.2 The rendezvous 503
20.3 Timing and scheduling 508
20.4 Protected objects 513
20.5 Simple select statements 521
20.6 Timed and conditional calls 524
20.7 Concurrent types and activation 527
20.8 Termination, exceptions, and ATC 534
20.9 Signalling and scheduling 540
20.10 Summary of structure 546
21 Object Oriented Techniques 551
21.1 Extension and composition 551
21.2 Using interfaces 554
21.3 Mixin inheritance 560
21.4 Linked structures 562
21.5 Iterators 565
21.6 Generalized iteration 570
21.7 Object factories 577
21.8 Controlling abstraction 581
22 Tasking Techniques 587
22.1 Dynamic tasks 587
22.2 Multiprocessors 590
22.3 Synchronized interfaces 598
22.4 Discriminants 609
22.5 Task termination 614
22.6 Clocks and timers 617
22.7 The Ravenscar profile 626
Program 4 Super Sieve 627
Appendices 851
A1 Reserved Words, etc. 851
A1.1 Reserved words 851
A1.2 Predefined attributes 852
A1.3 Predefined aspects 859
A1.4 Predefined pragmas 862
A1.5 Predefined restrictions 864
A2 Glossary 867
A3 Syntax 873
A3.1 Syntax rules 873
A3.2 Syntax index 891
A4 Introducing Ada 2022 901
A5.6a Generalized literals 902
A7.3a Iteration filters 902
A8.8 General aggregates 903
A9.5 Declare expressions 904
A9.6 Reduction expressions 905
A13.7a Renaming objects and values 906
A15.5a Aspect No_Return 907
A16.2a Default initial conditions 907
A16.2b Contracts and access types 908
A16.6 Global state 908
A19.2a Default generic parameters 912
A20.2a Entries, aspects, and synchronization 913
A21.6a Iterator interfaces 914
A21.6b Procedural iterators 915
A22.7a Profiles 917
A22.8 Parallel blocks and loops 917
A22.9 Conflict checking 919
A23.4a Big numbers 920
A23.4b Random numbers 927
A23.6a Images 927
A23.6b Text buffers 928
A24a Containers 931
A24.2a Doubly linked lists 931
A24.3a Vectors 939
A24.4a Maps 941
A24.5a Sets 942
A24.6a Trees 943
T his is being written shortly after the successful launch of the James Webb Space
Telescope, a demonstration of what can be achieved if enough care is taken with
the software engineering.
It is also on the cusp between 2021 and 2022, a time to both look backwards and
to look forward. It is a similar matter with Ada 2022. On one hand, it looks back,
filling in gaps in what should, with the benefit of hindsight, have already been in
earlier editions of Ada. On the other hand, it looks forward to a world where many-
core processors are ubiquitous and need to be made use of efficiently.
The Ada programming language continues to evolve in order to better support
the development of software applications with high requirements for reliability and
system integrity. The 4th major revision of the language, Ada 2022, includes
improvements in many different areas, but with particular focus on a few topics:
• allowing software developers to easily and safely take advantage of the parallel
execution capabilities of multi-core and multi-threaded architectures;
• allowing developers to more precisely express their intent regarding a
program’s structure and logic via improved contracts and other forms of
assertions;
• providing improved support for containers;
• providing “creature comforts” to ease the use of common programming idioms.
The introduction of parallel loops and parallel block statements allows users to
express the possibility of parallel execution of constructs that also have well-
defined sequential semantics. The Global and Nonblocking aspects can be used to
enable static detection of unsafe concurrent access to variables.
Contracts are improved along two different axes: contracts are supported in
more contexts (e.g., the Default_Initial_Condition aspect and support for
precondition/postcondition specifications for access-to-subprogram types and for
generic formal subprograms), and more expressive forms of expressions are defined
in order to make it possible to write more precise contracts (e.g., declare
expressions, reduction expressions, delta aggregates, and calls to static functions).
There is a sometimes-unappreciated point about some of these expression forms that
may seem like just syntactic sugar (another example is Ada 2012’s quantified
expressions). It is true that the same value could be computed in a function body
xv
without too much trouble, but then what would the postcondition be for this
function? How would the declaration of the function describe its result? So these
new forms do enable more expressive contracts.
Support is added for iterating over containers, and for constructing container
values using aggregates. The mechanisms used to accomplish this can also be used
in user-defined container implementations; the implementation-defined containers
have no special “magic” that is unavailable to users who want to “roll their own”.
Support is also provided for literals of private types, for indexing operations on a
private type, for implicit dereferencing of certain non-access types; all of these are
intended to make it easier to hide the implementation of a private type without
taking useful functionality away from clients. And the private type in question may,
of course, be a container type.
“Creature comforts” include the introduction of some features that have long
been available in other programming languages. A name ("@") is defined for the
target of an assignment statement, as in:
Function_Call.Some_Long_Name(Some_Index_Expression) : = @ + 1;
The Image attribute is now available for almost all types and objects, not just
for scalars; support for (in effect) user-specified Image functions is provided.
Restrictions on aggregates are relaxed (index values can now be used in array
aggregate component expressions); a discriminant value in an aggregate can be non-
static in more cases. Predefined support for big numbers (integer and real) is added.
Internationalization support is improved via the various new Wide_File_Names and
Wide_Wide_File_Names packages.
And there are many, many other improvements to the language as well. The
Jorvik profile, the System.Atomic_Operations package, the Object_Size attribute,
iterator filters, and lots of other stuff.
And who better to guide a user through all of this material than John Barnes?
John has been involved in Ada programming language design efforts since shortly
after the birth of Ada Lovelace (or so it seems). He combines his detailed
knowledge of the subject with a special talent for exposition. He has an unusual
ability to anticipate, and correct for, the ways that a reader might be confused by
whatever corner of the language he is describing. His choices of examples are
invariably both enlightening and entertaining. His writing combines technical
correctness with accessibility and humor.
For folks who want to write software that works correctly (admittedly, a small
audience), there is value in learning about Ada and, in particular, about Ada 2022.
And for anyone who wants to learn about Ada, there is both value and fun in
learning about it from John’s fine book.
Enjoy!
Steve Baird & Jeff Cousins,
Current and Past Chairs of the
ISO/IEC JTC1/SC22/WG9
Ada Rapporteur Group (ARG)
xvii
In order to avoid the book becoming unwieldy, the full details of the syntax for
Ada 2022 and an updated table summarising the containers in Ada 2022 are
provided on the website. The answers to all exercises are also on the website but
those for the introductory Part 1 are also included in the book for the convenience
of readers encountering Ada for the first time. More details of the website will be
found below.
Whenever a new standard appears and is put into use, it is almost inevitable that
various imperfections are soon discovered. Ada 2012 was no exception and a
number of corrections and improvements were deemed to be necessary. These
alterations were processed in the usual manner by the Ada Rapporteur Group and
resulted in a Corrigendum which was approved and published by ISO in February
2016. The body of this version of Programming in Ada 2012 accordingly covers this
updated 2016 standard. I have also taken the opportunity to convert the uses of
pragmas such as Pure and Preelaborate to aspect clauses in order to smooth the
transition to Ada 2022.
The revisions are described by Ada Issues (AIs) and a number of these are
mentioned in the Index. The early ones relate to the 2016 corrigendum but most
concern the evolution of Ada 2022.
And now I must thank all those who have helped with this new book both by
pointing out errors in the first edition and by reviewing the text of this new edition
and especially the Ada 2022 material. Many thanks therefore (in alphabetical order)
to Steve Baird, Janet Barnes, Ben Brosgol, Randy Brukardt, Jeff Cousins, Bob Duff,
Tama McGlinn, Pascal Pignard, and Tucker Taft. Their much valued comments
enabled me to improve the presentation and to eliminate a number of errors. I must
also give extra thanks to Randy Brukardt without whose eternal energy as editor of
the Ada standard, I would find writing about Ada a very difficult task indeed.
Finally, many thanks to my wife Barbara for help in typesetting and proof-
reading and to friends at Cambridge University Press for their continued guidance
and help.
John Barnes
Caversham, England
January 2022
‘The summer right evil weather, and dear; the boll of malt five merk
and half merk, and the boll of meal four merk and three merk. Evil
August; wind and rain. The harvest evil weather that ever was seen;
continual weet.’—C. F.
Consequently, in autumn and winter, ‘there was ane great dearth in
Scotland of all kinds of victuals.’—D. O. ‘About Lammas, wheat was
sold at London for three shillings the bushel; but shortly after it was
raised to four shillings, five shillings, six shillings, and before
Christmas to a noble and seven shillings, which so continued long
after. Beef was sold for twenty pence and two-and-twenty pence the
stone, and all other flesh and white meats at an excessive price; all
kind of salt fish very dear, as five herrings twopence. Yet great
plenty of fresh fish, and oft times the same very cheap.... All this
dearth notwithstanding (thanks be given to God) there was no want
of anything to him that wanted not money.’—Howes.
Towards the end of this year, the Regent Morton was at Dumfries,
holding justice-courts for the punishment of the Borderers. ‘Many
were punished by their purses rather than their lives. Many
gentlemen of England came thither to behald the Regent’s court,
where there was great provocation made for the running of horses.
By chance my Lord Hamilton had there a horse sae weel bridled and
sae speedy, that although he was of a meaner stature than other
horses that essayit their speed, he overran them all a great way
upon Solway Sands, whereby he obtained great praise both of
England and Scotland at that time.’—H. K. J.
‘The first day of May, 1576 years, was sae evil, the
wind and weet at the west-north-west, with great May 1.
showers of snaw and sleet, that the like was nocht
seen by them that was living, in mony years afore, sae evil.’—Chr.
Aber.