Control Structures Flashcards

1
Q

What are Expressions?

A

Type of program phrase that returns a value but does not change the state or perform a side-effect.

Functional programming only uses expressions!

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

What are Commands?

A

Type of program phrase that does not return a value but changes the state or performs a side effect

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
Describe the following notations:
function application notation
prefix notation
infix - notation
postfix - notation
A

FAN: +(a, b)

prefix: + a b
infix: a + b
postfix: a b +

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

What is the difference between eager evaluation and lazy evaluation?

A

Eager evaluation is evaluating an application of an operator to expressions by first evaluating the arguments and then applying the correct operation to the values

Lazy evaluation is to start by applying the operation and evaluate the arguments only as/if you need them

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

Two models of variables

A

A variable points to a value

A variable points to a location in the heap containing a value (the variable being a pointer and all…)

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

What are l and r expressions?

A

l-expressions denote locations, r-expressions are values storable in those locations

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

An assignment is executed by…

A

evaluating the LHS to an l-value
evaluating the RHS to an r-value
overwriting the content of the l-value with the r-value

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

What are the basic structured forms of control of a high-level imperative language?

A

Sequencing
Conditionals
Loops

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

Recursion is an alternative to loops for making a programming language…

A

Turing-complete

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

A function call is tail recursive if…

A

a call to function g in a function f is tail recursive if f returns the result of g without performing any further computation

A function is tail recursive if all calls in it are tail calls

A call to a tail recursive function only needs a single frame

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

What is a subprogram?

A

A function : meant to return a value and typically does not change the outside environment

A procedure: not meant to return a value, but changes the outside environment

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

Describe Call By Value

A
  • input only communication
  • parameter can be any expression
  • On the call, the parameter is evaluated to an r-value that is associated to the formal parameter
  • On the return, the formal parameter is destroyed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Describe Call By Reference

A
  • gives bidirectional communication
  • The parameter must be an l-expression
  • On the call it is evaluated to an l-value and that is associated to the formal parameter, aliasing it
  • On the return. the association of the formal parameter to this l-value is destroyed, but the l-value remains
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Describe Call By Constant

A
  • If the formal parameter is not modified in the body of the procedure, then call by value can be implemented by call by reference
  • The l-value of the actual parameter is passed to the procedure, the r-value is not, it is not copied to the frame of the call
  • Semantically this is just call by value but implemented differently
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Describe Call By Result

A
  • Output only communication
  • The actual parameter must be an l-expression, on the call it is evaluated to an l-value.
  • on the return the current r-value of the formal parameter is stored in this l-value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Describe Call By Value-Result

A
  • Combination of by value and result, gives bidirectional communication
  • The actual parameter must be an l-expression. On the call it is evaluated to an l-value and further to an r-value. The r-value is associated to the formal parameter
  • Upon return, the final r-value of the formal parameter is stored in the l-value of the actual parameter
17
Q

Describe Higher-order functions

A

Takes functions as parameters or returns a function

18
Q

Higher-order functions deep binding vs shallow binding

A

Deep binding: Use the environment active when the link between h and f is established

Shallow binding: Use the environment active when the call to f occurs

19
Q

What happens when an exception is raised?

A

Active blocks are exited until the closest protected block is found trapping this exception

The handler statically linked to this protected block is executed and the protected block is exited

Exceptions are propagated out along the dynamic chain