Book contents
- Frontmatter
- Contents
- List of Boxes
- Preface
- Part I Introduction
- Part II Action Notation
- Part III Semantic Descriptions
- Chapter 11 Statements
- Chapter 12 Literals
- Chapter 13 Expressions
- Chapter 14 Declarations
- Chapter 15 Variables
- Chapter 16 Subprograms
- Chapter 17 Tasks
- Part IV Conclusion
- Appendices
- Bibliography
- Symbol Index
- Concept Index
Chapter 16 - Subprograms
Published online by Cambridge University Press: 19 January 2010
- Frontmatter
- Contents
- List of Boxes
- Preface
- Part I Introduction
- Part II Action Notation
- Part III Semantic Descriptions
- Chapter 11 Statements
- Chapter 12 Literals
- Chapter 13 Expressions
- Chapter 14 Declarations
- Chapter 15 Variables
- Chapter 16 Subprograms
- Chapter 17 Tasks
- Part IV Conclusion
- Appendices
- Bibliography
- Symbol Index
- Concept Index
Summary
Subprograms are classified as procedures or functions.
Procedures are parameterized statements. They may be declared, and then called with various actual parameters. Formal parameter declarations resemble incomplete constant and variable declarations.
Functions are essentially parameterized expressions.
The semantics of subprogram declarations and calls illustrates the use of the reflective action notation introduced in Chapter 9, as well as the declarative action notation introduced in Chapter 7.
Semantic entities now include subprogram entities, which are formed from abstractions, and data that are used to distinguish subprogram returns from other reasons for abnormal termination of statement execution.
A procedure is a construct that incorporates a statement, which is known as the body of the procedure. A procedure declaration binds an identifier to a procedure. A procedure call statement causes the body of the identified procedure to be executed. In a few languages, procedures are provided as expressions; then a procedure declaration may be written just like an ordinary constant declaration.
A function is like a procedure, but a function body is essentially an expression, rather than a statement: it has to return a result. A function call is a kind of expression. In practice, most conventional programming languages allow impure functions, where the body is a mixture of statements and an expression.
- Type
- Chapter
- Information
- Action Semantics , pp. 177 - 194Publisher: Cambridge University PressPrint publication year: 1992