[plt-scheme] trying to figure out the do form

From: Sanjeev Sharma (throwit1 at hotmail.com)
Date: Mon Oct 11 18:38:17 EDT 2004

I thought these 2 would be equivalent, and the description seems to say they 
should be.

My self-appointed exercise was to move the update clauses around, so the (- 
i 1) was deleted from the (var val update) line & put into the do-if-false 
expression list.

Can someone show me where I'm messing up?

(define factorial
    (lambda (n)
    (do ((i n (- i 1)) (a 1 (* a i)))
        ((zero? i)(display "ans is  ")(display `("i, a",i",",a))(newline))
      (display `("i, a",i", ",a))(newline))))
(factorial 4)
(define factorial
  (lambda (n)
    (do ((i n ) (a 1 (* a i)))
      ((zero? i) (display "ans is  ")(display `("i, a",i",",a))(newline))
      (display `("i, a",i", ",a))(newline)(set! i(- i 1)))))
(factorial 4)

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/



Posted on the users mailing list.