Concepts of Programming Languages

(Sean Pound) #1
Summary 435

SUMMARY


Process abstractions are represented in programming languages by subpro-
grams. A subprogram definition describes the actions represented by the
subprogram. A subprogram call enacts those actions. A subprogram header
identifies a subprogram definition and provides its interface, which is called
its protocol.
Formal parameters are the names that subprograms use to refer to the
actual parameters given in subprogram calls. In Python and Ruby, array and
hash formal parameters are used to support variable numbers of parameters.
Lua and JavaScript also support variable numbers of parameters. Actual param-
eters can be associated with formal parameters by position or by keyword.
Parameters can have default values.
Subprograms can be either functions, which model mathematical func-
tions and are used to define new operations, or procedures, which define new
statements.
Local variables in subprograms can be stack dynamic, providing sup-
port for recursion, or static, providing efficiency and history-sensitive local
variables.
JavaScript, Python, Ruby, and Lua allow subprogram definitions to be
nested.
There are three fundamental semantics models of parameter passing—in
mode, out mode, and inout mode—and a number of approaches to implement-
ing them. These are pass-by-value, pass-by-result, pass-by-value-result, pass-
by-reference, and pass-by-name. In most languages, parameters are passed in
the run-time stack.
Aliasing can occur when pass-by-reference parameters are used, both
among two or more parameters and between a parameter and an accessible
nonlocal variable.

Figure 9.4


Coroutine execution
sequence with loops


........


resume A
.
.
.

B......


resume B
.
.
.
.
.

A
resume
from master

First

resume

Subsequent
resume


  • • • • • •











    • • • • • • • • • • •



Free download pdf