Lesson 3 Flashcards
Why do we want Object Oriented Programming?
Small number of independent parts => Simplicity, Generality
=>
Easy to learn
Productive
Maintainable
Modularity
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
Operating System Interface
OS is just a collection of objects, directories, files, display, mouse, keyboard primitive types
(define count
(let ((result 0))
(lambda ()
(set! result (+ result 1))
result)))
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…
substitute model vs environment model
subst: (eval exp)
env: (eval exp env)
we look up variables in the env for the values
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
what is variable lookup?
- look in current env. if found, return value
- look in parent env
- if not in global, unbound variable
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?
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.
What are mutable and immutable objects in python?
Mutable: Lists, Dictionaries, Sets
Immutable: Numbers, Strings, Tuples
What are sentinels/dummy nodes for?
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
what does tail recursion mean?
the function at the end of the stack can return immediately because there is no work left to be done in the calling function