Lecture 6 Flashcards

1
Q

What is a binding?

A

The relation between a syntactic element (keyword) and its meaning during execution

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

What is binding time?

A

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)

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

What is link time bindings?

A

Meaning is established when code is linked to external libraries

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

What is load time bindings?

A

Meaning is established when program is loaded into memory

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

What is run-time bindings?

A

Meaning established when program is executed.

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

What are early binding times?

A

All binding times up to the load time, inclusive

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

What is late binding times?

A

Run time bindings (start-up time, module, entry time, elaboration time, procedure call time, etc)

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

How are global values allocated in memory?

A

Allocated statically, location of object is fixed at load time.

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

How is procedure memory allocated?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How are the components of OZ layed out in memory?

A

Semantic stack: corresponds to stack-allocated call frames.

Assignment store: heap

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

What is implicit and explicit memory allocation

A

Automatic(procedure call/return) and manual(in program) allocation and dealocation

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

What is object and reference lifetime?

A

Object: Time between allocation and deallocation

reference: Time between creation, in environment, and deletion of mapping

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

What is static and dynamic scoping?

A

Static (lexical): A textual region of the code

Dynamic: A fragment of proceeding computation

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

When does some garbage collectors remove memory?

A

When there are no longer references to parts of memory.

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

What is dangling references?

A

When a pointer to a local variable is returned. This local variable will be deallocated when function returns, leaving the pointer dangling.

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

How does dynamic scoping work?

A

Identifiers are looked up in the caller’s environment, rather than the environment when the identifier first was created.

17
Q

What is a recursive procedure?

A

A proc that calls itself within its own body

18
Q

What is a recursive computation?

A

A recursive procedure is called repetitively so that the result of each calldepends on the result of the subsequent calls

19
Q

What is a property of a recursive computation?

A

The nested call is not the last statement.

20
Q

What is the difference between iteration and recursion?

A

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

21
Q

What is tail recursion?

A

Recursive procedures that specify iterative processes.
Constant stack size.
Recursive call is the last one to be executed within the body.

22
Q

What is last call optimization?

A

The technique that allows a tail-recursive procedure to return immediately instead of going through stacked callframes.

23
Q

Implement {Length L} recursively and tail-recursively

A

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

24
Q

What is a context?

A

A semantic statement on the stack

24
Q

What is the syntax for raise and try catch statements?

A

fun {Func X Y}

raise ‘this is an exception’ end
end

try
{Func 1 4}
catch ‘this is an exception’
// handle
end

25
Q

What is the execution rule for a try statement?

A

try <s1> catch <id> then <s2> end</s2></id></s1>

Push:
catch <id> then <s2> end</s2></id>

push:

<s1>
</s1>

26
Q

What is the semantics of raise?

A

(raise <id> end, E)</id>

Pop from stack until we find <id> in a catch</id>

Stop with error if stack empty and this is not found

If found, push to stack the statement within the catch (<s2>)
E = Ec + {<id> -> E(<id>)}</id></id></s2>

27
Q

What is an n+1 order procedure?

A

At least 1 argument is an n-order procedure

28
Q

What is procedural abstraction?

A

Converting statement into procedure

29
Q

What is Instantiation?

A

Producing procedures by calling procedure-generating procedures with appropriate arguments

30
Q

What is genericity?

A

Abstracting out part of the procedure body into an argument

31
Q

What is embedding?

A

Including procedures in data structures.

32
Q
A
33
Q

Create a generic Map function

A

{Map List Op}
case List of nil then nil
[] H|T then {Op H} | {Map T Op}
end

34
Q

What is right- and left folding?

A

Folds a list in a right-associative manner.
(1+(2+(3+(4+0)))

Left:
((((1+2)+3)+4)+0)

35
Q

Create a generic rightfold function

A

fun {Rightfold List Op Combine}
case List of nil then nil
[] H|T then
{Combine {Op H} {Rightfold T Op Combine}}
end
end

36
Q

Create a Map function using rightfold

A

fun {Map List Op}
{Rightfold List Op fun {$ Head Tail} Head|Tail}
end