Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise 6.7.13: Consider the following Scheme program. 1 (define n (lambda (n)

ID: 3728135 • Letter: E

Question

Exercise 6.7.13: Consider the following Scheme program. 1 (define n (lambda (n) (map (1ambda (n) 7 (n (2 4 6)) 8 (4 8 12) 6.7. COMPARISON OF STATIC AND DYNAMIC SCOPING 255 a) Annotate this program with comments referring to line numbers on lines 5-7 to indicate which declaration of n on lines 1, 2, and 4 the refer- ences to n on lines 5-7 are bound b) Annotate this program with comments referring to lines numbers on lines 1, 2, and 4 to indicate the scope of the declarations of n on lines 1 2, and 4

Explanation / Answer

a.

1 > (define n

2 (lambda (n)

3 (map

4 (lambda (n)

5 (* n 2)) # this n is in referance to line 1

6 n))) # this n is in referance to line 4

7 > (n '(2 4 6))

8 (4 8 12) # this n is in referance to line 1

b.

1 > (define n # scope of n is full function

2 (lambda (n) # scope is in bracket only so local scope

3 (map

4 (lambda (n) # scope is in bracket only so local scope

5 (* n 2))

6 n)))

7 > (n '(2 4 6))

8 (4 8 12)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote