Newsgroups: comp.software-eng,comp.theory,comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!news.sprintlink.net!mv!moreira.mv.com!alberto
From: alberto@moreira.mv.com (Alberto C Moreira)
Subject: Re: Style: multiple returns and relatives
Distribution: inet
Message-ID: <alberto.540.00173EC9@moreira.mv.com>
Organization: MV Communications, Inc.
Date: Sat, 18 Nov 1995 04:14:33 GMT
References: <RMARTIN.95Nov10210926@oma.com> <dclineDHw7yv.Kx1@netcom.com> <4867u4$of1@ratty.wolfe.net> <alberto.529.00005178@moreira.mv.com> <48d026$eeq@Starbase.NeoSoft.COM> <alberto.534.00162922@moreira.mv.com> <48ief9$b2o@hermes.acs.unt.edu>
X-Newsreader: Trumpet for Windows [Version 1.0 Rev A]
X-Nntp-Posting-Host: moreira.mv.com
Lines: 58
Xref: glinda.oz.cs.cmu.edu comp.software-eng:38995 comp.theory:14585 comp.lang.scheme:14322

In article <48ief9$b2o@hermes.acs.unt.edu> srt@zaphod.csci.unt.edu (Steve Tate) writes:

>Alberto C Moreira (alberto@moreira.mv.com) wrote:
>> In article <48d026$eeq@Starbase.NeoSoft.COM> claird@Starbase.NeoSoft.COM (Cameron Laird) writes:

>> >Certainly Scheme is a fine language, with many advantages over C; however,
>> >it still has to answer comparable questions about style.  How,
>> >for example, do Schemers code a Fibonacci function, 

>>         (define fib
>>            (lambda (n)
>>                (if (< n 2)
>>                    n
>>                    (+ (fib (- n 1)) (fib (- n 2))  ))))

>One of the great benefits of Scheme is that people learn recursion
>really well, whereas I have many data structures students this
>semester who are having big problems with the entire concept (the
>intro courses use Pascal here, and are moving to C++, which won't help
>this problem).

>On the other hand, one of the great curses of learning Scheme first is
>that people tend to use recursion for *everything*, even in horribly
>inefficient places like this.  The above implementation takes
>exponential time, whereas an iterative version (assuming constant time
>per arithmetic operation) takes linear time.  So using recursion here
>turns something that should be fairly efficient into something that is
>simply horribly, horribly inefficient.

       Actually, good Schemes may put my program in tail recursive
       form and generate pretty fast iterative code from it. Or I can
       write it in tail form myself:

           (define fib
              (lambda (n)
                  (tailfib n 0 1)  ))

           (define tailfib
              (lambda (n a b)
                  (if (= n 0)
                      b
                      (tailfib (- n 1) b (+ a b))  )))

>There are times when recursion is great, but this ain't one of 'em!

       I believe that decoupling the specification of a function from its 
       performance limitations is a good thing. If we know that the
       compiler or interpreter has the power to turn our formally
       excellent but possibly slow code into a fast object-code
       spaghetti mess, we get the best of both worlds: a sound, whole
       programming language, and decently fast object code.


                                                  _alberto_




