Path: news.net.uni-c.dk!newsfeeds.net.uni-c.dk!newsfeed1.uni2.dk!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-ge.switch.ch!in2p3.fr!univ-lyon1.fr!unice.fr!not-for-mail From: Philippe TEISSIER Newsgroups: comp.lang.beta Subject: Re: Making a simple program to learn Date: Thu, 15 Feb 2001 22:26:37 +0100 Organization: University of Nice-Sophia Antipolis Lines: 42 Message-ID: <3A8C4980.68357CBD@chez.com> References: <3A8C4777.A078783F@chez.com> NNTP-Posting-Host: adp-22.unice.fr Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; x-mac-type="54455854"; x-mac-creator="4D4F5353" Content-Transfer-Encoding: 7bit X-Trace: malibu.unice.fr 982272358 28232 134.59.69.31 (15 Feb 2001 21:25:58 GMT) X-Complaints-To: usenet@malibu.unice.fr NNTP-Posting-Date: 15 Feb 2001 21:25:58 GMT X-Mailer: Mozilla 4.7 (Macintosh; I; PPC) X-Accept-Language: en Xref: news.net.uni-c.dk comp.lang.beta:12713 In this code, the case n < 1 is not seen, so the programm will loop. What must I add to stop the loop at n<=1 In scheme, the code would look like that: (define (prod_imp n) (if (< n 1) 1 (if (= (mod n 2) 1) (* n (prod_imp (- n 2))) (prod_imp (- n 1))))) or faster: (apply * (filter odd? (iota 1 n))) What do you advise me ? Thanx Philippe TEISSIER wrote: > Hi > > I 'm learning Scheme, and I visited Beta Homepage because my teacher > advised me to do so > > what would be a small pattern giving the product of the n first odd > numbers as a result. > > I thought of > > prod_imp: (# n: @integer; > enter (n) > (if n mod 2 = 0 then exit (n-1) else exit (n * > ((n)->prod_imp)) if) > #); > > But the compiler is to big to DL for my small modem. > Is this expression correct, if not, could you explain what correction I > need to do? > > Thanx a lot > > Philippe TEISSIER > philippe.teissier@unice.fr