Instant Download Programming in Ada 2012 1st Edition Barnes PDF All Chapters
Instant Download Programming in Ada 2012 1st Edition Barnes PDF All Chapters
Instant Download Programming in Ada 2012 1st Edition Barnes PDF All Chapters
com
https://ebookname.com/product/programming-in-ada-2012-1st-
edition-barnes/
OR CLICK BUTTON
DOWNLOAD EBOOK
https://ebookname.com/product/concurrent-and-real-time-programming-in-
ada-3rd-edition-alan-burns/
ebookname.com
https://ebookname.com/product/beginning-visual-c-2012-programming-1st-
edition-karli-watson/
ebookname.com
https://ebookname.com/product/clearly-visual-basic-programming-with-
microsoft-visual-basic-2012-3rd-edition-diane-zak/
ebookname.com
https://ebookname.com/product/the-fourth-perimeter-first-edition-tim-
green/
ebookname.com
Earthquake Resistant Engineering Structures VIII Wit
Transactions on the Built Environment C. A. Brebbia
https://ebookname.com/product/earthquake-resistant-engineering-
structures-viii-wit-transactions-on-the-built-environment-c-a-brebbia/
ebookname.com
https://ebookname.com/product/lincoln-on-race-and-slavery-henry-louis-
gates-editor/
ebookname.com
600 Essential Words for the TOEIC 3rd Edition Lin Lougheed
https://ebookname.com/product/600-essential-words-for-the-toeic-3rd-
edition-lin-lougheed/
ebookname.com
https://ebookname.com/product/shakespeare-s-theater-a-sourcebook-1st-
edition-tanya-pollard/
ebookname.com
https://ebookname.com/product/ipod-the-missing-manual-eleventh-
edition-j-d-biersdorfer/
ebookname.com
Biochemical pharmacology 1st ed Edition Michael Palmer
https://ebookname.com/product/biochemical-pharmacology-1st-ed-edition-
michael-palmer/
ebookname.com
Programming
in Ada 2012
Programming
in Ada 2012
JOHN BARNES
University Printing House, Cambridge CB2 8BS, United Kingdom
www.cambridge.org
Information on this title: www.cambridge.org/9781107424814
A catalogue record for this publication is available from the British Library
Foreword xv
Preface xix
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
viii Contents
25 Interfacing 781
25.1 Representations 781
25.2 Unchecked programming 785
25.3 The package System 788
25.4 Storage pools and subpools 790
25.5 Other languages 797
27 Finale 823
27.1 Names and expressions 823
27.2 Type equivalence 827
27.3 Overall program structure 830
27.4 Portability 834
27.5 Penultimate thoughts 836
27.6 SPARK 839
Contents xiii
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
And now – Ada 2012, the latest version of the language whose description you are
holding, reflects both aspects of this dialectic process: it introduces new ways of
thinking about program construction, and it reflects developments in software
practice that hark back to the earlier days of our profession but that have seldom, if
ever, found their way into well-established programming languages.
xv
xvi Foreword
The general rubric for these new/old ideas is Programming by Contract. The term
became well-known through the pioneering work of Bertrand Meyer and the design
of Eiffel, but it probably found more significant use in the SPARK community, in the
design of critical software for applications that require a real measure of formal
verification for their deployment.
Ada 2012 offers the programmer a wealth of new tools for specifying the intent
of a program: preconditions, postconditions, type invariants, subtype predicates. All
of these allow the software architect to present more clearly the intent of a piece of
software, and they allow the compiler and/or the run-time system to verify that the
software behaves as intended. The use of pre- and postconditions was proposed a
generation ago by E. DIkjstra and C.A.R .Hoare, but their pioneering efforts were
not widely adopted by the software community, among other things because good
language support for these mechanisms was lacking. Their introduction in a
language whose user community is particularly concerned with mission-critical
software reflects the fact that concerns about safety and security are more urgent
than ever. We can expect that these techniques will be adopted early and
enthusiastically by the aerospace and automotive software development
community, as they have been in the small and dedicated SPARK community.
Preconditions, postconditions, type invariants and type predicates are logical
assertions about the behavior of a given construct. When these assertions involve
data aggregates (vectors, sets, and other container types) it is particularly
convenient to use notations from first-order logic, namely quantified expressions.
An important syntactic innovation of Ada 2012 is the introduction of quantified
expressions both in their universal form (all elements of this set are French Cheeses)
and their existential form (some element of this vector is purple). As a result, the
language includes the new keyword some. These quantified expressions are of
course implicit loops over data aggregates, and in parallel with their introduction,
Ada 2012 has extended considerably the syntax of iterators over containers. A
generalized notion of indexing now allows the programmer to define their own
iterable constructs, as well as mapping between arbitrary types.
Contracts, quantified expressions, and generalized indexing may appear to be
miscellaneous additions to an already large language; in fact they are elegantly
unified under the umbrella of a new construct: the Aspect Specification, which also
generalizes and unifies the earlier notions of attributes and pragmas. The coherence
of the language has thus been enhanced as well.
Programming languages must also respond to developments in Computer
Hardware. The most significant development of the last decade has been the
appearance of multicore architectures, which provide abundant parallelism on a
single chip. Making efficient use of the computer power now available on a single
processor has been the goal of much development in language design. Ada 2012
provides tools for describing multicore architectures, and for mapping computing
activities onto specific cores or sets of them.These are novel capabilities for a
general-purpose programming language, and we can expect them to have a
profound impact on the practice of parallel programming.
This thumbnail description of the high points of the new version of the language
is intended to whet your appetite for the pages that follow. Once again, John Barnes
has provided a wonderfully lucid, learned, and insightful description of the latest
version of Ada. He has been the tireless explicator of the design and evolution of
the language over more than three decades, and the Ada community has acquired its
Foreword xvii
understanding and love of the language from his prose. A programming language is
a tool for thought, and most Ada users have learned how to think about programs
from John Barnes’s books. I can only hope that the widest possible audience will
learn to think straight from the exciting descriptions that follow.
The design of Ada 2012 is once again the result of the collective effort of the
Ada Rapporteur group, an extremely talented group of language designers who
combine deep industrial experience with an equally deep knowledge of
programming language semantics and theoretical computer science. The ARG, of
which John Barnes has been an invaluable member from the inception of Ada, has
once again created a modern and elegant programming language that addresses the
needs of a new generation of software designers. It has been an enormous privilege
to work with them. I trust the reader will enjoy the result of their work for years to
come. Happy Programming!
Ed Schonberg
AdaCore
Chairman, Ada Rapporteur Group
New York, March 2014
Preface
elcome to Programming in Ada 2012 which has been triggered by the recent
W ISO standardization of Ada 2012.
The original language, devised in the 1980s, is known as Ada 83 and was
followed by Ada 95, Ada 2005, and now Ada 2012. Ada has gained a reputation as
being the language of choice when software needs to be correct. And as software
pervades into more areas of society so that ever more software is safety critical or
security critical, it is clear that the future for Ada is bright. One observes, for
example, the growth in use of SPARK, the Ada based high integrity language widely
used in areas such as avionics and signalling.
Ada 83 was a relatively simple but highly reliable language with emphasis on
abstraction and information hiding. It was also notable for being perhaps the first
practical language to include multitasking within the language itself.
Ada 95 added extra flexibility to the strongly typed and secure foundation
provided by the Software Engineering approach of Ada 83. In particular it added the
full dynamic features of Object Oriented Programming (OOP) and in fact was the
first such language to become an ISO standard. Ada 95 also made important
structural enhancements to visibility control by the addition of child units, it greatly
improved multitasking by the addition of protected types, and added important basic
material to the standard library.
Ada 2005 then made improvements in two key areas. It added more flexibility
in the OOP area by the addition of multiple inheritance via interfaces and it added
more facilities in the real-time area concerning scheduling algorithms, timing and
other matters of great importance for embedded systems. It also added further
facilities to the standard library such as the ability to manipulate containers.
Ada 2012 makes further important enhancements. These include features for
contracts such as pre- and postconditions, tasking facilities to recognize multicore
architectures, and major additions and improvements to the container library.
In more detail, the changes include
xix
xx Preface
• Expressions – the introduction of the contract material showed a need for more
flexible expressions. Accordingly, Ada now includes conditional expressions,
case expressions, quantified expressions and more flexible forms of
membership tests. A new form of function is also introduced in which the body
is essentially given by a single expression.
• Structure and visibility – perhaps the most startling change in this area is
allowing functions to have parameters of all modes. This removes the need for
a number of obscure techniques (dirty tricks really) which had been used.
Other important improvements concern incomplete types.
• Tasking – Ada 2012 has new features describing the allocation of tasks to
individual processors and sets of processors; these additions were prompted
by the rapid growth in the use of multicore architectures.
• Generally – new flexible forms of iterators and dereferencing are introduced
mainly for use with containers. Better control of storage pools is permitted by
the introduction of subpools.
• Predefined library – some improvements are made concerning directories
and a feature is added for the identification of locale. However, the most
important improvement is the addition of many new forms of containers.
These include multiway trees and task-safe queues. There are also bounded
forms of all containers which are important for high integrity systems where
dynamic storage management is often not permitted.
The finale includes, as in its predecessors, with the fantasy customer in the shop
trying to buy reusable software components and whose dream now seems as far
away or indeed as near at hand as it did many years ago when I first toiled at this
book. The discussion continues to take a galactic view of life and perhaps echoes
the cool cover of the book which depicts the Ice Comet.
Preface xxi
Those familiar with Programming in Ada 2005 might find the following
summary of key changes helpful
• The number of chapters has grown from 25 to 27. The new chapter 8 covers the
new forms of expressions such as if expressions, case expressions, and
quantified expressions. The new chapter 16 discusses the material on contracts.
The chapter on containers (now chapter 24) has grown because of the
introduction of containers for multiway trees, single indefinite objects, and
various forms of queues. A number of existing chapters have additional sections
such as that on aliasing.
• The revisions to produce Ada 2012 have impacted to a greater or lesser extent
on many aspects of the language. Most chapters conclude with a checklist
summarizing important points to remember and listing the main additions in
Ada 2012.
• As a consequence the book is now some 120 pages longer. It would have been
even longer had I not decided that it was unnecessary to include the answer to
every exercise. Accordingly, the printed answers cover just the introductory
chapters (for the benefit of those entirely new to Ada) and those exercises that
are referred to elsewhere in the book. But all the answers are on the associated
website.
The website also includes the six sample programs both in text form and as
executable programs, some material from earlier versions of this book which now
seem of lesser importance but which I nevertheless was reluctant to lose completely.
More details of the website will be found below.
And now I must thank all those who have helped with this new book. The
reviewers included Janet Barnes, Alan Burns, Rod Chapman, Jeff Cousins, Bob
Duff, Stuart Matthews, Ed Schonberg, Tucker Taft, and Andy Wellings. Their much
valued comments enabled me to improve the presentation and to eliminate a number
of errors. Some of the new material is based on parts of the Ada 2012 Rationale and
I must express my special gratitude to Randy Brukardt for his painstaking help in
reviewing that document.
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
March 2014
An Overview
Chapter 1 Introduction 3
Chapter 2 Simple Concepts 11
Chapter 3 Abstraction 27
Chapter 4 Programs and Libraries 47
Program 1 Magic Moments 59
T
his first part covers the background to the Ada language and an
overview of most of its features. Enough material is presented
here to enable a programmer to write complete simple
programs.
Chapter 1 contains a short historical account of the origins and
development of various versions of Ada from Ada 83 through Ada 95
and Ada 2005 and leading to Ada 2012 which is the topic of this book.
There is also a general discussion of how the evolution of abstraction
has been an important key to the development of programming
languages in general.
Broadly speaking, the other three chapters in this part provide an
overview of the material in the corresponding other parts of the book.
Thus Chapter 2 describes the simple concepts familiar from languages
such as C and Pascal and which form the subject of the seven chapters
which comprise Part 2. Similarly Chapter 3 covers the important topic
of abstraction which is the main theme of Part 3. And then Chapter 4
rounds off the overview by showing how a complete program is put
together and corresponds to Part 4 which covers material such as the
predefined library.
1
Chapter 3 includes a discussion of the popular topic of object
oriented programming and illustrates the key concepts of classes as
groups of related types, of type extension and inheritance as well as
static polymorphism (genericity) and dynamic polymorphism leading
to dynamic binding. It also includes a brief comparison between the
terminology used by Ada and that used by some other languages. This
chapter concludes with an introduction to tasking which is a very
important aspect of Ada and is a topic not addressed by most
programming languages at all.
This part concludes with the first of a number of complete programs
designed to give the reader a better understanding of the way the
various components of the language fit together. This particular
program illustrates a number of aspects of type extension and
polymorphism.
Those not familiar with Ada will find that this part will give them
a fair idea of Ada’s capabilities and lays the foundation for
understanding the details presented in the remainder of the book.
2
1 Introduction
3
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of Loinen
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.
Title: Loinen
Kertomus
Author: K. A. Järvi
Language: Finnish
Kirj.
K. A. Järvi
— Pyh!
— Pastori.
— On pastorin vuoro.
— Isäntä on hyvä.
Hävytön!
Rovasti lupaa hovilaiselle niin paljon kaunista, että hän yhä heltyy,
melkein sielulliseen hekumaan hukkuu.
Kun hän kulkee, avautuu nyt tie hänelle kuin keisarille, jonka
ohimoilla on kultainen kruunu.
— Todellakin?
— Diakonissakassaan?
— Niin.
— Siihenkin!
— Lasketaanko lisää?