From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,baaf5f793d03d420 X-Google-Attributes: gid109fba,public X-Google-Thread: fc89c,97188312486d4578 X-Google-Attributes: gidfc89c,public X-Google-Thread: 1014db,6154de2e240de72a X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,97188312486d4578 X-Google-Attributes: gid103376,public From: miker3@ix.netcom.com (Mike Rubenstein) Subject: Re: What's the best language to start with? [was: Re: Should I learn C or Pascal?] Date: 1996/08/13 Message-ID: <320fed48.8431764@nntp.ix.netcom.com>#1/1 X-Deja-AN: 173823252 references: <31FBC584.4188@ivic.qc.ca> <01bb83ad$29c3cfa0$87ee6fce@timpent.airshields.com> <4u89c4$p7p@solutions.solon.com> <01bb83f5$923391e0$87ee6fce@timpent.airshields.com> <4uah1k$b2o@solutions.solon.com> <01bb853b$ca4c8e00$87ee6fce@timpent.airshields.com> <320b35a2.43769707@nntp.ix.netcom.com> <01bb8609$59339140$87ee6fce@timpent.airshields.com> <320bf032.7193774@nntp.ix.netcom.com> <01bb8802$a5ff3a60$32ee6fce@timhome2> <320f14e5.213196860@nntp.ix.netcom.com> <4uo4b8$ug0@excessus.demon.co.uk> organization: Netcom x-netcom-date: Mon Aug 12 9:54:46 PM CDT 1996 newsgroups: comp.lang.c,comp.lang.c++,comp.unix.programmer,comp.lang.ada Date: 1996-08-12T21:54:46-05:00 List-Id: mdw@excessus.demon.co.uk (Mark Wooding) wrote: > Mike Rubenstein wrote: > > "Tim Behrendsen" wrote: > > > > > I'm not sure if that's good or not. One of the famous ways to > > > show recursion is a factorial computation. Does that mean we > > > actually *want* people to implement factorial that way? > > > > In scheme (and some other languages) it certainly is the way to > > implement it. > > Are we talking about implementing it the truly stupid way as a single > function, e.g., > > (define (factorial n) > (if (zero? n) > 1 > (* n (factorial (- n 1))))) > > or properly using another function which tail-recurses, e.g., > > (define (factorial n) (fact-assist 1 n)) > (define (fact-assist a n) > (if (zero? n) > a > (fact-assist (* a n) (- n 1)))) > > If the former, then please report for re-education; if the latter, then > well and good: tail recursion is the functional-language equivalent of a > loop in a language like C. The first version above is similar in style > (and in the sorts of problems it causes) to the traditional > > int factorial(int n) { return (n ? n*factorial(n-1) : 1); } > > recursive C implementation, while the second is similar in spirit to the > iterative version. > > (My Scheme isn't terribly good: please don't moan at me about it if it's > wrong or nasty. Also, all of the routines above assume they get valid > inputs, and will do really bad things if they don't: issues of input > checking aren't really relevant to the discussion in hand.) Obviously, one should do it right. Dybvig, for example, explains why the tail recursive version is better without resorting to assembly language :-) Michael M Rubenstein