darthsabbath
December 18th, 2005, 07:57 AM
Hi, all,
I'm working through "The Structure And Interpretation of Computer Programs", and... wow... heavy stuff. But I had a question on something that's a bit confusing, and I was hoping someone who's read it may have some insight. In Section 1.2.1, it goes into Linear Recursion and Iteration, and it has some (at least from what I consider) disparaging remarks on the idea of loop constructsfrom other languages such as for, while, etc, instead seeming to prefer what it calls an iterative process... for example:
(define (factorial n)
(fact-iter 1 1 n))
(define (fact-iter product counter max-count)
(if (> counter max-count)
product
(fact-iter (* counter product)
(+ counter 1)
max-count)))
While at heart it seems that the two are the same, but I was wondering, in a non-Lisp based language such as Python or C, would there be any advantage to using an example such as that listed above compared to a for or while statement? I fail to see the point, unless I'm completely missing something or haven't gotten far enough into the book. It merely calls loops "syntactic sugar."
Phil
I'm working through "The Structure And Interpretation of Computer Programs", and... wow... heavy stuff. But I had a question on something that's a bit confusing, and I was hoping someone who's read it may have some insight. In Section 1.2.1, it goes into Linear Recursion and Iteration, and it has some (at least from what I consider) disparaging remarks on the idea of loop constructsfrom other languages such as for, while, etc, instead seeming to prefer what it calls an iterative process... for example:
(define (factorial n)
(fact-iter 1 1 n))
(define (fact-iter product counter max-count)
(if (> counter max-count)
product
(fact-iter (* counter product)
(+ counter 1)
max-count)))
While at heart it seems that the two are the same, but I was wondering, in a non-Lisp based language such as Python or C, would there be any advantage to using an example such as that listed above compared to a for or while statement? I fail to see the point, unless I'm completely missing something or haven't gotten far enough into the book. It merely calls loops "syntactic sugar."
Phil