Chapter 9 Flashcards

1
Q

What are the three general characteristics of subprograms?

A

Each subprogram has a single entry point.
The calling program unit is suspended during the execution of the called subprogram, which implies that there is only one subprogram in execution at any given time.
Control always returns to the caller when the subprogram execution terminates.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a subprogram call?

A

It is the explicit request that a specific subprogram.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a subprogram definition?

A

It describes the interface to and the actions of the subprogram abstraction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What characteristic of Python subprograms sets them apart from those of other languages?

A

It is that function def statements are executable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do Ruby methods differ from the subprograms of other programming languages?

A

Ruby methods are often defined in class definitions but can also be defined outside class definitions.
If a Ruby method is called without a receiver, self is assumed.
If there is no method by that name in the class, enclosing classes are searched, up to Object, if necessary.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the feature of Lua functions?

A

Although they’re anonymous, they can be defined using syntax that makes it appear as though they have names.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are function declarations called in C and C++? Where are the declarations often placed?

A

Function declarations in C and C++ are called prototypes and they are often placed in header files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Name one pure functional programming language that does not have mutable data.

A

Haskell

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are positional parameters?

A

The correspondence betweenn actual and formal parameters-or the binding of actual parameters to formal parameters-is done by position: The first actual parameter is bound to the first formal parameter and so forth.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Give an example of a language that allows positional parameters in addition to keyword parameters.

A

Python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the use of a default value?

A

It is used if no actual parameter is passed to the formal parameter is passed to the formal parameter in the subprogram header.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the rule of using a default parameter in C++?

A

The default parameters must appear last, because parameters are positionally associated.
Once a default parameter is omitted in a call, all remaining formal parameters must have default values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the rule for accepting variable parameters in C# methods?

A

The parameters have to be of the same type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What language allows array formal parameters?

A

Ruby

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is an ellipsis?

A

(…) Can be treated as an array or as a list of values that can be assigned to a list of variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the modes, the conceptual models of transfer, the advantages, and the disadvantages of pass-by-value, pass-by-result, pass-by-value-result, and pass-by-reference parameter-passing methods?

A

pass-by-value:
the value of the actual parameter is used to initialize the corresponding formal parameter. This formal parameter is then used as a local variable in the subprogram. Since the subprogram is receiving data from the actual parameter, this is a model of in-mode semantics. Pass-by-value is implemented using copy where an actual value is copied then transmitted and by passing an access path to the value of the actual parameter. Copy implementation is more efficient, because when using an access path the value is stored in a write protected cell that is not always simply enforced.
ADVANTAGE: speed, since there’s no need to go find an actual value.
DISADVANTAGE: if a copy is used then that copy must be stored, and that storage could be costly if using a large variable.

pass-by-result:
no value is transmitted to the subprogram. The formal parameter acts like a local variable, and before control is transferred back to the caller, the variables’ value is transmitted back to the actual parameter. It transmits data back to the actual parameter. It is an out-mode semantic. Most typically pass-by-result uses a copy conceptual model.
ADVANTAGE: same as pass-by-value
DISADVANTAGE: same as pass-by-value & there can be an actual parameter collision because order of expressions matter.

pass-by-value-result:
a combination of pass-by-value and pass-by-result. The value of the actual parameter is used to initialize the corresponding formal parameter, which then acts as a local variable. The formal parameters must have local storage associated with the called subprogram. At termination, the subprogram transmits the value of the formal parameter back to the actual parameter. As such, it uses inout-mode semantics and copy passing conceptual model.
ADVANTAGE: same as pass-by-value and pass-by-result. It solves pass-by-reference’s aliasing problems.
DISADVANTAGE:
same as pass-by-value and pass-by- result.

pass-by-reference:
an address(reference to the memory location of the actual parameter) is passed to the subprogram. Another example of an inout-mode semantic. An example of an access path conceptual model.
ADVANTAGE: efficient in both time and space since there is no duplicate space required or copying.
DISADVANTAGE: the increase in time to access formal parameters because of the additional level of indirect addressing; if only one way communication to the called subprogram is required, inadvertent and erroneous changes may be made to the actual parameter; aliasing should be expected; broadens access to nonlocal variables; the aliasing problems lead to decreased readability and reliability.

17
Q

Describe the ways that aliases can occur with pass-by-reference parameters.

A

Through collisions between formal parameters and non-local variables that are visible.

18
Q

What is the difference between the way original C and C89 deal with an actual parameter whose type is not identical to that of the corresponding formal parameter?

A

In the original C, neither the number of parameters not their types were checked. In C89, the formal parameters of functions can be defined in two ways.

19
Q

Name some languages that support procedures.

A

Ada, Fortran

20
Q

Describe the problem of passing multidimensioned arrays as parameters.

A

A separately compiled subprogram needs to know the declared size of array parameter to build the storage mapping function.

21
Q

What is the name of the parameter-passing method used in Ruby?

A

Passed-by-assignment

22
Q

What are the two issues that arise when subprogram names are parameters?

A

Are parameter types checked?
What is the correct referencing environment for a subprogram that was sent as a parameter?

23
Q

Define shallow and deep binding for referencing environments of subprograms that have been passed as parameters.

A

Shallow Binding: the environment of the call statement that enacts the passed subprogram(most natural for dynamic-scoped languages)

Deep Binding: the environment of the definition of the passed subprogram(most natural for static-scoped languages)

24
Q

What is a generic subprogram?

A

parametrically polymorphic subprograms; a subprogram that takes generic parameters that are used in type expressions that describe the types of the parameters of the subprogram.

25
Q

What is an ad hoc binding?

A

the environment of the call statement that passed the subprogram as an actual parameter

26
Q

What causes a C++ template function to be instantiated?

A

becoming typed classes at compile time.

27
Q

In what fundamental ways do the generic methods of Java 5.0 differ from those of C# 2005?

A

The actual type parameters in a call can be omitted if the compiler can infer the unspecified type in C# and C# 2005.

28
Q

If a Java 5.0 method returns a generic type, what type of object is actually returned?

A

The generic type casted to the proper type.

29
Q

If a Java 5.0 generic method is called with three different generic parameters, how many versions of the method will be generated by the compiler?

A

-

30
Q

When does a variable have unlimited extent?

A

when its lifetime is that of the whole program

31
Q

What is subtype polymorphism?

A

A variable of type T can access any object of type T or any type derived from T(OOP languages)

32
Q

What is a multicast delegate?

A

a delegate that stores multiple addresses

33
Q

What is the main drawback of generic functions in F#?

A

It is not always able to determine the type of parameters or the return type of a function.

34
Q

What is a coroutine?

A

It is a special kind of subprogram.

35
Q

What are the language characteristics that make closures useful?

A

Language in which a subprogram can access variables in nesting scopes and it can be called anywhere

36
Q

What languages allow the user to overload operators?

A

Ada, C++, Python, Ruby

37
Q

What is a symmetric unit control model?

A

It is the coroutine control mechanism.