CSE 130 Lecture Notes - Lecture 5: Call Stack, Lookup Table, Free Variables And Bound Variables

23 views2 pages
Published on 24 Jan 2018
School
Course
Professor
Can we eta-reduce?
λg.(λx. xy)g = λx.x y ← Yes! G is useless
λx.λy.x y = λx.x ← NO! X is bound to the outer x, so we cannot remove it
λy.x y ← Yes!
Scoping
Why would u not want to do function application w/ substitution?
- Performance SUCKS (lots of memory used/wasted)
-variable mutation does NOT work!
- Ex: z = 0 → z++
Environment Model - between λ-calc and machine model
- Anatomy of a scope
- First-order functions
- Free variable
- High-order functions
Anatomy of a scope L R
let y = 1; | y | 1 |
let z = 0; | z | 0 1
Z++;
console.log(z) ^-environment (stack) ptr
Values and Locations
- R-values: plain old values
- L-values: refer to locations where r-values are stored; persist beyond single
expressions
What does ++ operator take? L-values (cannot take plain old #’s)
-Slow! Just do a lookup table to find location of vars!
When do we create an environment? Every time we enter a new block AND function
scope!
New block scope - {}
New function scope - create a new function()
Points to global environment! --> | control | |
function fact(n) {} Activation | n | 3 |
Record | ret | |
fact(3);
Control links: records where to switch the environment pointer when we finish
evaluating the scope
- Applies to block scopes too!
Return value: l-value where return value of function should be stored
Parameters: l-value for EACH formal parameter
Local variables: l-values for each let+const declaration
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Get OneClass Notes+

Unlimited access to class notes and textbook notes.

YearlyBest Value
75% OFF
$8 USD/m
Monthly
$30 USD/m
You will be charged $96 USD upfront and auto renewed at the end of each cycle. You may cancel anytime under Payment Settings. For more information, see our Terms and Privacy.
Payments are encrypted using 256-bit SSL. Powered by Stripe.