1 day ago
my attempt to do the exercises in sicp.
Tuesday, July 1, 2008
sicp exercise 1.41
; Exercise 1.41. Define a procedure double that takes a procedure of one argument as argument and
; returns a procedure that applies the original procedure twice. For example, if inc is a procedure
; that adds 1 to its argument, then (double inc) should be a procedure that adds 2. What value is returned
; by
; (((double (double double)) inc) 5)
(define (inc x) (+ x 1))
(define (double f) (lambda (x) (f (f x))))
(display (inc 10)) (newline)
(display ((double inc) 10)) (newline)
(display (((double (double double)) inc) 5)) (newline)
; (double double) means 4 times
; ((double (4 times)) means 4 times 4 = 16 times increment
; Ans: 21
(display (((double (double (double double))) inc) 10)) (newline)
; gives 16 times 16 = 256 increments
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment