# [plt-scheme] HTDP Section 22.1 some confusion...

 From: Matthias Felleisen (matthias at ccs.neu.edu) Date: Thu Apr 30 08:38:32 EDT 2009 Previous message: [plt-scheme] HTDP Section 22.1 some confusion... Next message: [plt-scheme] HTDP Section 22.1 some confusion... Messages sorted by: [date] [thread] [subject] [author]

```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-

=  ;; replace name by value
(define f ((lambda (x) (local ((define (x-adder y) (+ x y))) x-
=  ;; replace x by 5 (as in middle school)
=  ;; lift local as in 1
(define x-adder-never-mentioned-before (lambda (y) (+ 5 y)))
=
(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 >>
>
>
>
>
>>> 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 (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
>>> 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.
>
> _________________________________________________