[plt-scheme] HTDP Section 22.1 some confusion...
It's all substitution of values for parameters and renaming.
1. ... (local ((define f e)) b) ...
is equal to
;; at top level
(define f-never-mentioned-before e{with f replaced by f-never-
mentioned-before})
;; where local used to be
... b{with f replaced by f-never-mentioned-before} ...
2. ((lambda (x) e) 5)
is equal to
e{x is equal to 5}
So you have:
(define add (lambda (x) (local ((define (x-adder y) (+ x y))) x-
adder)))
(define f (add 5))
= ;; replace name by value
(define f ((lambda (x) (local ((define (x-adder y) (+ x y))) x-
adder)) 5))
= ;; replace x by 5 (as in middle school)
(define f (local ((define (x-adder y) (+ 5 y))) x-adder))
= ;; lift local as in 1
(define x-adder-never-mentioned-before (lambda (y) (+ 5 y)))
(define f x-adder-never-mentioned-before)
=
(define x-adder-never-mentioned-before (lambda (y) (+ 5 y)))
(define f x-adder-never-mentioned-before (lambda (y) (+ 5 y))))
On Apr 29, 2009, at 3:58 AM, Dave wrote:
>>> Hi,
>>> I'm a bit confused by the evaluation example given for the
>>> application of add to a number.
>>> please forgive my notation, I've started my lines with >>
>
>
> (define (add x)
> (local ((define (x-adder y) (+ x y))) x-adder))
>
>
>>> So we've got add which I think I understand fine, and now we're
>>> defining f as an application of add to a number.
>
>
> (define f (add 5))
> = (define f (local ((define (x-adder y) (+ 5 y))) x-adder))
>
>
>>> so far so good...
>
>
> = (define f (local ((define (x-adder5 y) (+ 5 y))) x-adder5))
>>>
>>> ^? ^?
>>> now what I don't understand is where the 5 in x-adder5 comes from.
>>> There's nothing actually called x-adder5, right? that line could
>>> equally say
>>> = (define f (local ((define (add5please y) (+ 5 y))) add5please))
>>> It's not like you can call (x-adder5 20) is it? you can only
>>> invoke x-adder5 with (f x)
>>> x-adder5 is just there to show that the newly defined function
>>> has the formerly free variable x now fixed to 5
>>> please let me know If I've got this the right way round in my
>>> mozgy gulliver.
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme