Path: news.net.uni-c.dk!howland.erols.net!newspharm.inet.tele.dk.MISMATCH!news.tele.dk!193.251.151.101!opentransit.net!jussieu.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: Mon, 19 Feb 2001 17:25:24 +0100 Organization: University of Nice-Sophia Antipolis Lines: 101 Message-ID: <3A9148F3.C684B273@chez.com> References: <3A8C4777.A078783F@chez.com> <3A8C4980.68357CBD@chez.com> NNTP-Posting-Host: adp-16.unice.fr Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; x-mac-type="54455854"; x-mac-creator="4D4F5353" Content-Transfer-Encoding: 8bit X-Trace: malibu.unice.fr 982599892 5800 134.59.69.25 (19 Feb 2001 16:24:52 GMT) X-Complaints-To: usenet@malibu.unice.fr NNTP-Posting-Date: 19 Feb 2001 16:24:52 GMT X-Mailer: Mozilla 4.7 (Macintosh; I; PPC) X-Accept-Language: en Xref: news.net.uni-c.dk comp.lang.beta:12719 Yep, I decided to spend time but do it yesterday, and after DL beta, and having trouble installing it on MacOs, I did it. It's not far from what you sent : (# produit_impairs: (# a,res: @integer; enter (a) do (if (a < 2) then 1->res else (if (a mod 2)//0 then ((a-1)->&produit_impairs)->res; else (((a-2)->&produit_impairs)*a)->res; if); if); exit res #); do 'Valeur? ' -> putText;(getint)->&produit_impairs->&putInt; #) Thanx Peter Andersen wrote: > 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 > >