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, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3e08c98d7ce85399 X-Google-Attributes: gid103376,public From: Robert Dewar Subject: Re: Eight Queens problem (was Re: Kindness) Date: 1999/09/08 Message-ID: <7r5mjn$c72$1@nnrp1.deja.com>#1/1 X-Deja-AN: 522499473 References: <37CC6844.AB898EEE@rational.com> <37CE93CD.799A225A@pwfl.com> <37CF0FE0.2B299477@acenet.com.au> <37CFF7DC.CFF9717C@pwfl.com> <1999Sep3.125818.1@eisner> <37D02CC0.BEF1BC69@mitre.org> <7r1c4c$9an$1@nnrp1.deja.com> <7r2fc6$1sc$1@nnrp1.deja.com> <7r4edb$gg2$1@nnrp1.deja.com> <7r50tj$sp3$1@nnrp1.deja.com> X-Http-Proxy: 1.0 x25.deja.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja.com - Share what you know. Learn what you don't. X-Article-Creation-Date: Wed Sep 08 12:59:41 1999 GMT X-MyDeja-Info: XMYDJUIDrobert_dewar Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.04 [en] (OS/2; I) Date: 1999-09-08T00:00:00+00:00 List-Id: In article <7r50tj$sp3$1@nnrp1.deja.com>, bourguet@my-deja.com wrote: > function fact(n : natural) return natural is > begin > if n = 0 then > return 1; > else > return n*fact(n-1); > end if; > end fact; > > tail recursive? There is a multiplication to be executed after > the return. You are right, it is not tail recursive as normally expressed, however the transformation here to a tail recursive version is a standard one (and one that is for example performed by many compilers). The real point is that you want to choose something which shows that recursion is useful, not merely a neat way of writing a simple loop in a kludgy manner, which will be quite inefficient if the compiler does NOT do pretty clever tail recursion elimination. I would not expect ANY Ada compiler to be that clever, and in fact, it would not surprise me to find that many Ada compilers do no tail recursion elimination at all. P.S. It is interesting how important this optimization can be. The Realia COBOL compiler does extensive tail recursion elimination (on the x86, in its simplest form, this consists of replacing a CALL x/RET sequence by JMP X), and it turned out to be a VERY important optimization. That sounds very strange, given that COBOL does not allow recursion, but of course general tail recursion elimination also catches the case of calling some *other* procedure as the last step. Sent via Deja.com http://www.deja.com/ Share what you know. Learn what you don't.