What are the three general characteristics of subprograms?
What does it mean for a subprogram to be active?
A subprogram is considered active if it has been called and has begun execution but has not yet completed that execution
What is given in the header of a subprogram?
A subprogram header specifies that the syntactic unit is a subprogram definition, provides a name for the subprogram (if it is not anonymous), and may optionally specify a list of parameters.
What characteristic of Python subprograms sets them apart from those of other languages?
In Python, function def statements are executable. This means a function cannot be called until its def statement has been executed, and different versions of a function can be defined based on control flow (e.g., inside an if statement)
What languages allow a variable number of parameters?
Languages that support a variable number of parameters include Python, Ruby, Lua, and JavaScript.
What is a parameter profile? What is a subprogram protocol?
What is a Ruby array formal parameter?
Ruby uses array formal parameters to support a variable number of parameters, allowing a subprogram to accept any number of actual parameters.
What are formal parameters? What are actual parameters?
What are the advantages and disadvantages of keyword parameters?
Advantage: They can appear in any order in the actual parameter list, which is helpful when parameter lists are long.
Disadvantage: The user of the subprogram must know the specific names of the formal parameters.
What are the differences between a function and a procedure?
Functions: These model mathematical functions, are used to define new operations, and return a value.
Procedures: These define new statements and do not return a value
What are the design issues for subprograms?
What are the advantages and disadvantages of dynamic local variables?
Advantages: They provide support for recursion and allow for memory conservation because storage is only allocated when the subprogram is active.
Disadvantages: They incur the overhead of allocation, recovery, and indirect addressing; additionally, they prevent subprograms from being history-sensitive (retaining values between calls).
What are the advantages and disadvantages of static local variables?
Advantages: They are very efficient because no run-time overhead is required for allocation or deallocation. Additionally, they allow subprograms to be history-sensitive, meaning they can retain values between activations.
Disadvantages: They lack support for recursion. Also, because storage is bound to the variables for the entire execution of the program, it cannot be shared with local variables of other subprograms.
What languages allow subprogram definitions to be nested?
Languages that allow nested subprogram definitions include JavaScript, Python, Ruby, and Lua.
What are the three semantic models of parameter passing?
In-mode: The formal parameter can receive data from the actual parameter.
Out-mode: The formal parameter can transmit data to the actual parameter.
Inout-mode: The formal parameter can both receive data from and transmit data to the actual parameter.
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?
Describe the ways that aliases can occur with pass-by-reference parameters.
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?
What are two fundamental design considerations for parameter-passing methods?
The two fundamental considerations are efficiency and whether the data transfer is one-way or two-way.
Describe the problem of passing multidimensioned arrays as parameters.
The primary problem is that the called subprogram needs to know the sizes of all but the first dimension to correctly compute the storage mapping function (address) for any given element. Without this information, the subprogram cannot calculate where an element like a[i][j] is located in the linear memory space.
What is the name of the parameter-passing method used in Ruby?
Ruby uses pass-by-value, but because all variables are references to objects, it is effectively “pass-by-value where the value is a reference” (often called pass-by-sharing)
What are the two issues that arise when subprogram names are parameters?
Define shallow and deep binding for referencing environments of subprograms that have been passed as parameters
What is an overloaded subprogram?
An overloaded subprogram is a subprogram that has the same name as another subprogram in the same referencing environment. Every version of an overloaded subprogram must have a unique protocol (parameter profile).