Book contents
- Frontmatter
- Contents
- Preface
- 1 Predicate Logic
- 2 The Simple Imperative Language
- 3 Program Specifications and Their Proofs
- 4 Arrays
- 5 Failure, Input-Output, and Continuations
- 6 Transition Semantics
- 7 Nondeterminism and Guarded Commands
- 8 Shared-Variable Concurrency
- 9 Communicating Sequential Processes
- 10 The Lambda Calculus
- 11 An Eager Functional Language
- 12 Continuations in a Functional Language
- 13 Iswim-like Languages
- 14 A Normal-Order Language
- 15 The Simple Type System
- 16 Subtypes and Intersection Types
- 17 Polymorphism
- 18 Module Specification
- 19 Algol-like Languages
- Appendix: Mathematical Background
- Bibliography
- Index
4 - Arrays
Published online by Cambridge University Press: 28 January 2010
- Frontmatter
- Contents
- Preface
- 1 Predicate Logic
- 2 The Simple Imperative Language
- 3 Program Specifications and Their Proofs
- 4 Arrays
- 5 Failure, Input-Output, and Continuations
- 6 Transition Semantics
- 7 Nondeterminism and Guarded Commands
- 8 Shared-Variable Concurrency
- 9 Communicating Sequential Processes
- 10 The Lambda Calculus
- 11 An Eager Functional Language
- 12 Continuations in a Functional Language
- 13 Iswim-like Languages
- 14 A Normal-Order Language
- 15 The Simple Type System
- 16 Subtypes and Intersection Types
- 17 Polymorphism
- 18 Module Specification
- 19 Algol-like Languages
- Appendix: Mathematical Background
- Bibliography
- Index
Summary
In this chapter, we extend the simple imperative language and the methods for reasoning about its programs to include one-dimensional arrays with integer subscripts. Although more elaborate and varied forms of arrays are provided by many programming languages, such simple arrays are enough to demonstrate the basic semantical and logical properties of arrays.
There are two complementary ways to think about arrays. In the older view, which was first made explicit in early work on semantics by Christopher Strachey, an array variable is something that one can apply to an integer (called a subscript) to obtain an “array element” (in Strachey's terminology, an “L-value”), which in turn can be either evaluated, to obtain a value, or assigned, to alter the state of the computation. In the newer view, which is largely due to Hoare but has roots in the work of McCarthy, an array variable, like an ordinary variable, has a value — but this value is a function mapping subscripts into ordinary values. Strachey's view is essential for languages that are rich enough that arrays can share elements. But for the simple imperative language, and especially for the kind of reasoning about programs developed in the previous chapter, Hoare's view is much more straightforward.
Abstract Syntax
Clearly, array variables are a different type of variable than the integer variables used in previous chapters.
- Type
- Chapter
- Information
- Theories of Programming Languages , pp. 81 - 96Publisher: Cambridge University PressPrint publication year: 1998