#python #sicp
Like local assignment, local def statements only affect the current local
frame. These functions are only in scope while sqrt is being evaluated.
Consistent with our evaluation procedure, these local def statements don't
even get evaluated until sqrt is called.
If you want to change selection, open document below and click on "Move attachment"
1.6 Higher-Order Functionsde the body of other
definitions.
>>> def sqrt(a):
def sqrt_update(x):
return average(x, a/x)
def sqrt_close(x):
return approx_eq(x * x, a)
return improve(sqrt_update, sqrt_close)
<span>Like local assignment, local def statements only affect the current local
frame. These functions are only in scope while sqrt is being evaluated.
Consistent with our evaluation procedure, these local def statements don't
even get evaluated until sqrt is called.
Lexical scope. Locally defined functions also have access to the name
bindings in the scope in which they are defined. In this example,
sqrt_update refers to the name a , which is Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details