Lecture 11 Flashcards
What is a subprogram definition?
It describes the interface and actions of the subprogram abstraction.
In Python, function definitions are executable; in other languages, they are non-executable.
In Ruby, function definitions can appear either in or outside class definitions.
In Lua, all functions are anonymous.
What is a subprogram call and header?
A subprogram call is an explicit request for the subprogram to be executed. A subprogram header is the first part of the definition, including the name, kind of subprogram, and formal parameters.
What is the parameter profile and protocol of a subprogram?
The parameter profile (signature) is the number, order, and types of parameters. The protocol includes the parameter profile and the return type if it is a function.
What are function declarations in C and C++ called?
They are often called prototypes. A subprogram declaration provides the protocol but not the body of the subprogram.
What are formal and actual parameters?
A formal parameter is a dummy variable listed in the subprogram header and used in the subprogram.
An actual parameter represents a value or address used in the subprogram call statement.
What are the fundamental characteristics of subprograms?
Each subprogram has a single entry point. The calling program is suspended during the execution of the called subprogram, and control always returns to the caller after the subprogram’s execution terminates.
What are positional and keyword parameter bindings?
Positional binding binds actual parameters to formal parameters by position. Keyword binding specifies the formal parameter name with the actual parameter, allowing parameters to appear in any order.
How are default parameter values handled in various languages?
Languages like C++, Python, Ruby, PHP allow formal parameters to have default values. In C++, default parameters must appear last due to positional association.
How do different languages handle variable numbers of parameters?
C# uses an array preceded by params. Ruby uses a hash literal with an asterisk. Python uses a list of values with an asterisk. Lua uses three periods as a formal parameter.
What are the differences between procedures and functions?
Procedures are collections of statements defining parameterized computations. Functions resemble procedures but are semantically modeled on mathematical functions and expected to produce no side effects.
What are the design issues for subprograms?
Issues include local variables’ static or dynamic nature, subprogram definitions in other subprograms, parameter passing methods, parameter type checking, functional side effects, return types and values, subprogram overloading, and generic subprograms.
What are the characteristics of stack-dynamic and static local variables?
Stack-dynamic local variables support recursion and share storage among subprograms but have allocation/de-allocation time and indirect addressing issues.
Static local variables have opposite advantages and disadvantages.
What do activation records contain?
Activation records contain local variables, parameters, return address, and control information necessary for procedure calls and returns.
What does procedure activation represent and what is an activation tree?
Procedure activation represents the actions when a caller invokes a callee, including the transfer of actuals into formals, allocation of memory for local variables, and identification of the control return point.
An activation tree graphically represents activations over time.
What are the design issues for functions?
Issues include allowing side effects, types of return values, return value restrictions, returning functions