-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol-1.41.tex
More file actions
20 lines (19 loc) · 774 Bytes
/
sol-1.41.tex
File metadata and controls
20 lines (19 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
The `double` procedure can be defined as follows:
\begtt\scm
(define (double f)
(lambda (x) (f (f x))))
\endtt
Then we can evaluate the given expression:
\begtt\scm
(((double (double double)) inc) 5)
;Value: 21
\endtt
Let's try to understand what's going on. Evaluating `(double double)` gives the procedure that applies `double` twice to its argument. Therefore, evaluating `(double (double double))` gives the procedure that applies `double` four times to its argument. This means that
\begtt\scm
((double (double double)) inc)
\endtt
is equivalent to
\begtt\scm
(double (double (double (double inc))))
\endtt
This last expression gives the procedure that applies `inc` to its argument $2^4=16$~times. When we apply it to the number~$5$ we get the result $5+16=21$.