Lesson 3 Flashcards

1
Q

Why do we want Object Oriented Programming?

A

Small number of independent parts => Simplicity, Generality
=>
Easy to learn
Productive
Maintainable

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

Modularity

A

As size increases, harder to build, harder to modify, harder to understand, harder to maintain
If any part of a system depends on the internals of another part, then complexity increases by square of the size of the system
N^2 dependencies

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

Operating System Interface

A

OS is just a collection of objects, directories, files, display, mouse, keyboard primitive types

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

(define count
(let ((result 0))
(lambda ()
(set! result (+ result 1))
result)))

A

persistent local state variables
each time we call count, result counter will increase
1
2
3
4
5

result is a free reference that is looked up in the environment
the environment binds the name to a box and we can change the box to 0, 1, 2…

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

substitute model vs environment model

subst: (eval exp)
env: (eval exp env)
we look up variables in the env for the values

A

substitute model evaluates arg expressions and substitue arg values in the procedure body and apply procedure to arglist
environment model evaluates arg expressions. make an environment with parameters bound to the arguments and evaluate the body in the environment. we create a new environment whenever we invoke a new function

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

what is variable lookup?

A
  1. look in current env. if found, return value
  2. look in parent env
  3. if not in global, unbound variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is the difference between dynamic scoping and lexical scoping?
x <- 1
f <- function(a) x + a
g <- function() {
x <- 2
f(0)
}
g() # what does this return?

A

lexical scoping - inside g, f(0) will return 1 because x is bound to 1
dynamic scoping - inside g, f(0) will return 3 because most recent value of x is 2.

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

What are mutable and immutable objects in python?

A

Mutable: Lists, Dictionaries, Sets
Immutable: Numbers, Strings, Tuples

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

What are sentinels/dummy nodes for?

A

It allows us to avoid running off the table and takes care of edge cases
It allows us to keep pointer to the structure the same even if the structure has changed because the dummy node will stay the same

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

what does tail recursion mean?

A

the function at the end of the stack can return immediately because there is no work left to be done in the calling function

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