Lecture 6 Flashcards
What is a binding?
The relation between a syntactic element (keyword) and its meaning during execution
What is binding time?
The time at which the meaning of a syntactic entity is established.
E.g. during language design time (C keyword static), or during programming (C keyword int, because programmer need to specify size).
Compile time (when syntactic elements are linked to external libraries)
What is link time bindings?
Meaning is established when code is linked to external libraries
What is load time bindings?
Meaning is established when program is loaded into memory
What is run-time bindings?
Meaning established when program is executed.
What are early binding times?
All binding times up to the load time, inclusive
What is late binding times?
Run time bindings (start-up time, module, entry time, elaboration time, procedure call time, etc)
How are global values allocated in memory?
Allocated statically, location of object is fixed at load time.
How is procedure memory allocated?
On stack, FIFO
Procedure calls sets up a call frame that is allocated on stack.
This includes callers address, local vars, result vars, arguments for further calls.
How are the components of OZ layed out in memory?
Semantic stack: corresponds to stack-allocated call frames.
Assignment store: heap
What is implicit and explicit memory allocation
Automatic(procedure call/return) and manual(in program) allocation and dealocation
What is object and reference lifetime?
Object: Time between allocation and deallocation
reference: Time between creation, in environment, and deletion of mapping
What is static and dynamic scoping?
Static (lexical): A textual region of the code
Dynamic: A fragment of proceeding computation
When does some garbage collectors remove memory?
When there are no longer references to parts of memory.
What is dangling references?
When a pointer to a local variable is returned. This local variable will be deallocated when function returns, leaving the pointer dangling.
How does dynamic scoping work?
Identifiers are looked up in the caller’s environment, rather than the environment when the identifier first was created.
What is a recursive procedure?
A proc that calls itself within its own body
What is a recursive computation?
A recursive procedure is called repetitively so that the result of each calldepends on the result of the subsequent calls
What is a property of a recursive computation?
The nested call is not the last statement.
What is the difference between iteration and recursion?
In iteration, the stack is kept constant in size.
Recursion:
declare
fun {Factorial N}
if N < 2 then 1
else N * {Factorial N - 1} end
end
Iteration:
declare
fun {Factorial N}
fun {Iterate Iterator Accumulator}
if Iterator >N then Accumulator
else {Iterate Iterator+1 Accumulator*Iterator} end end in
{Iterate 2 1}
end
What is tail recursion?
Recursive procedures that specify iterative processes.
Constant stack size.
Recursive call is the last one to be executed within the body.
What is last call optimization?
The technique that allows a tail-recursive procedure to return immediately instead of going through stacked callframes.
Implement {Length L} recursively and tail-recursively
Recursive:
fun {Length L}
case L of nil then 0
[] H|T then
1 + {Length Tail}
end
end
Iteratively:
fun {Length L}
fun {Iterate L A}
case L of nil then A
[] H|T then {Iterate T A+1}
end
in
{Iterate L 0}
end
What is a context?
A semantic statement on the stack