[taos-glug] 1.41 "double"; 1.42 "compose"

  • From: Philip Ansteth <pansteth@xxxxxxxxxxx>
  • To: taos-glug@xxxxxxxxxxxxx
  • Date: Sat, 9 Aug 2003 20:24:20 -0600

This idea of "first class" status for procedures is neat.

However, I don't know about exercises 1.41 and 1.42.

First, what is the answer to 1.41?

I say 21.   Here's what I get:

guile> ((double inc) 0)
2
guile> ((double inc) 2)
4
guile> (((double (double double)) inc) 5)
21
guile> (((double (double double)) inc) 0)
16
guile> 


However, I don't think that, comparing exercises 1.41 and 1.42, the above can 
be correct.

For the wording, "applies the original procedure twice" in 1.41, I coded

(define (double f)
  (lambda (arg)
    (f (f arg))))

For the wording, "composition f after g" in 1.42, I coded

(define (compose f g)
  (lambda (arg)
    (f (g arg))))

These give the right answers for the examples, but what about the question of 
1.41

(((double (double double)) inc) 5) 

for which no answer is given?

My initial guess for, 1.41, "applied the original procedure twice" didn't give 
the
right result:

;; this must be wrong
(define (double f)
  (lambda (arg)
    (begin
      (f arg)
      (f arg))))

The above doesn't give (double inc) being a procedure that adds two.   Rather
it just adds one, throws away the result, and then adds one, which is not
the same as adding two.

I conclude, and therefore criticize the authors, because either
(1)  the wording of 1.41 is unclear
or 
(2) 1.41 and 1.42 are the same exercise using two different words, "double" and 
"compose," to refer
to the same idea:

    ((double inc) 2) -> 4
    ((compose inc inc) 2) ->4

Either alternative is sloppy use of English.


Other related posts:

  • » [taos-glug] 1.41 "double"; 1.42 "compose"