One in which type errors are always detected, either at compile-time or run-time.
What's a function SIDE-EFFECT?
If a function changes any non-local variable.
What is REFERENTIAL TRANSPARENCY?
If any two expressions in the proram that have the same value can be substituted for one another anywhere in the program, without affecting the action of the program.
What is SHORT CIRCUIT evaluation?
A speed-up technique used by compilers to evaluate an expression without evaluating all the operands or operators.
What is COERCION?
Implicit type-conversion of operands (done by the compiler).
What is widening coercion?
Converts to a type that can include at least approximations to all the values of the original type. For example, int to float, but not float to int.
What is narrowing coercion?
Converts an object to a type that cannot include all of the values of the original type. For example, float to int.
What problem did STRUCTURED PROGRAMMING fix?
Importance of control statements in producing "understandable programs".
What's the purpose of a multiple selection statement?
Generalization of two-way selection statement to allow selection among any number of clauses.
What are the language design issues for multiple selection?
Is execution flow through the structure restricted to include just a single selectable segment? (i.e. is there an implicit branch at the end of each selectable segment?)
What is done if the control expression has no specified clause? (i.e. is there a "default" clause?)
What type of control expression(s) are allowed?
How are selectable segments specified?
How are case values specified?
What are the 4 ways to control an iteration (Loop)?
What are the design issues for counter controlled loops?
What is the type and scope of the loop variable?
Can the loop variable be changed in the loop body?
Are loop parameters evaluated once or at every iteration?
Is branching into the loop body allowed?
What's a pre-test loop?
Test at beginning of loop.
What's a post-test loop?
Test at end of loop.
What C,C++, Java statements allow user controlled loops?
BREAK & CONTINUE
How does data controlled iteration work with an ITERATOR?
Returns the next element in the data structure in some order.
What are three pre-defined iterators in PHP or Ruby?
What kind of "abstraction" do subprograms provide.
What is a DEFINITION?
Describes the interface and the actions of the subProgram.
What is a DECLARATION?
Provides the protocol but not the body of a subprogram. A.k.a. "Prototypes" in C and C++.
What is a HEADER?
The first part of the definition that includes the name, kind of subProgram, formal parameters.
What is a SIGNATURE?
The number, order, and types of a subProgram's parameters. (a.k.a parameter profile) --
What is a PROTOCOL?
A subProgram's signature and, if it is a function, its return type.
What is a formal parameter?
A dummy variable listed in the header and used in the subprogram.
What is an actual parameter?
Represents a value used in the subprogram call statement.
It is assigned to a formal parameter.
What is an advantage and disadvantage of keyword parameters?
Advantage: Parameters can appear in any order, avoiding parameter correspondence errors.
Disadvantage: Programmer must know the formal parameter's name.
static vs stack-dynamic local variables
Stack-dynamic allows recursion but subprogram cannot be history sensitive using only stack-dynamic variables.
Static allows history sensitive, but no recursion.
What are 3 semantic modes of parameter passing?
In mode (pass-by-value)
Out mode (pass-by-result)
Know the 3 ways to implement InOut mode?
In C, C++, What information must be included in the formal parameters of multi-dimensional arrays, and why is this needed?
In C, C++, the programmer must include the declared sizes of all but the first subscript in the formal parameter.
This info is needed for the compiler to be able to construct the access function of the parameter.
What is done at run-time in Ada, C#, Java that provides the above information to subprograms without making the programmer specify it?
Declared array size is part of array's runtime type descriptor.
Arrays are objects.
Use the environment of the call statement that calls the passed subprogram.
Most natural for dynamic-scoped languages.
Use the environment of the definition of the passed subprogram.
Most natural for static-scoped languages.
Use the environment of the call statement that passed the subprogram as an actual parameter.
How do C, C++ implement indirect subprogram calls?
Call a function through a pointer.
How does C# implement indirect calls?
What is an OVERLOADED subprogram?
Has the same name as another subprogram in the same referencing environment.
What is a GENERIC subprogram?
a.k.a Polymorphic subprogram
Takes parameters of different types.
Each call of the subprogram with particular data types for the arguments generates a different ACTIVATION (a.k.a. specialization) of the subprogram.
AD HOC POLYMORPHISM
Overloaded subprograms provide this type of polymorphism
Usually provided in languages with object-oriented support.
It means a variable of type T can access any object of type T or any type derived from T.
Subprogram takes generic parameters (a.k.a. "typename" parameters in C++) that are used to describe the data types of the parameters of the subprogram.
What's a CLOSURE?
A subprogram and the referencing environment where it was defined.
How does a CLOSURE work?
Referencing environment needed if subprogram can be called from any arbitrary place in the program.
A static-scoped language that doesn't permit nested subprograms doesn't need closures.
Closures only needed if a subprogram can access variables in nesting scopes and it can be called from anywhere.
To support closures, an implementation may need to provide whole program lifetime to some variables, because a subprogram may access a nonlocal variable that is normally no longer alive.
How do COROUTINES work?
A coroutine call is named a RESUME.
First resume of a coroutine is to its beginning.
Subsequent calls enter at the point just after the last executed statement of the coroutine.
All the local variables in the coroutine retain their values from the last execution.
Coroutines repeatedly resume each other.
What is a SubProgram LINKAGE?
The call and return operations of a language.
What's in an activation record?
stack-dynamic local variables
Saves the old EP as the dynamic link and creates a new value.
Allocates local variables in the activation record.
moves values of out or inout mode parameters to actual parameters.
make return value accessable to caller.
restore stack pointer by setting it to EP-1.
set EP to the old dynamic link.
restore execution status of caller.
transfer control (back to caller's return address)
What is a block?
User-specified local scopes for variables.
What are two ways to implement blocks?
Treat blocks as subprograms with no parameters that are always called from the same location. Create an activation record every time the block is executed.
Since maximum storage for a block can be statically determined, statically allocate the space for variables within the block after the local variables in the activation record of the enclosing subprogram.
DEEP access to nonlocal variables
Reference nonlocal stack-dynamic variables in a dynamic-scoped language by searching through the activation records of the other subprograms that are currently active, beginning with most recently activated.
Similar to accessing nonlocal variables in static-scoped language except dynamic chain is followed rather than the static chain.
Every activation record must include variable names.
ADV/DISADV: fast subprogram linkage, but references to nonlocals, especially distant ones, are slower.
SHALLOW access to nonlocal variables
Eliminate searching activation records by maintaining a table of information about all the variables.
Must add new (local) variables to the table at each subprogram call, and remove them on return.
ADV/DISADV: fast access to nonlocal variables, especially distant ones, but subprogram linkage is slower due to updating the table at each call and return.
What are two ways to implement shallow access?
Central table of nonlocal variable names with ACTIVE bit. Table offset of each nonlocal reference is determined at compile time.
Table containing a separate stack for each variable name. Push each time the name is declared. Always reference top of stack.