Path: news.net.uni-c.dk!not-for-mail From: Peter Andersen Newsgroups: comp.lang.beta Subject: Re: Making a simple program to learn Date: Mon, 19 Feb 2001 11:19:45 +0100 Organization: UNI-C Lines: 82 Message-ID: References: <3A8C4777.A078783F@chez.com> <3A8C4980.68357CBD@chez.com> NNTP-Posting-Host: bifrost.mjolner.dk Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Trace: news.net.uni-c.dk 982577831 37812 130.225.4.254 (19 Feb 2001 10:17:11 GMT) X-Complaints-To: usenet@news.net.uni-c.dk NNTP-Posting-Date: Mon, 19 Feb 2001 10:17:11 +0000 (UTC) User-Agent: Microsoft-Entourage/9.0.2509 Xref: news.net.uni-c.dk comp.lang.beta:12718 How about: prod_imp: integerValue (# n: @integer; enter n do (if n<1 then 1 -> value else (if (n mod 2)=1 then n*(n-2)->&prod_imp -> value else (n-1)->&prod_imp -> value if) if) #) Where integerValue is predefined in the BETA environment: integerValue: (# value: @integer; do INNER exit value #) I an not a Scheme expert, though (:-) -- Sincerely, Peter Andersen Mjølner Informatics On 15/02/01 22:26, in article 3A8C4980.68357CBD@chez.com, "Philippe TEISSIER" wrote: > 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 >