comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Dewar <robert_dewar@my-deja.com>
Subject: Re: Eight Queens problem (was Re: Kindness)
Date: 1999/09/08
Date: 1999-09-08T00:00:00+00:00	[thread overview]
Message-ID: <7r5mjn$c72$1@nnrp1.deja.com> (raw)
In-Reply-To: 7r50tj$sp3$1@nnrp1.deja.com

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.




  reply	other threads:[~1999-09-08  0:00 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-31  0:00 Kindness Mark Lundquist
1999-09-02  0:00 ` Kindness Marin David Condic
1999-09-03  0:00   ` Kindness Geoff Bull
1999-09-03  0:00     ` Kindness Marin David Condic
1999-09-03  0:00       ` Kindness Larry Kilgallen
1999-09-03  0:00         ` Kindness Robert I. Eachus
1999-09-04  0:00           ` Eight Queens problem (was Re: Kindness) Daryle Walker
1999-09-05  0:00             ` Robert Dewar
1999-09-14  0:00               ` Robert I. Eachus
1999-09-06  0:00             ` Vladimir Olensky
1999-09-06  0:00               ` Robert Dewar
1999-09-07  0:00                 ` bourguet
1999-09-08  0:00                   ` Robert Dewar
1999-09-08  0:00                     ` bourguet
1999-09-08  0:00                       ` Robert Dewar [this message]
1999-09-08  0:00                         ` Ted Dennison
1999-09-03  0:00         ` Kindness tmoran
1999-09-03  0:00           ` Kindness Marin David Condic
     [not found]         ` <37D55622.69B27515@rational.com>
1999-09-07  0:00           ` Homework (was Re: Kindness) Larry Kilgallen
1999-09-08  0:00             ` Ted Dennison
1999-09-08  0:00           ` Homework Mark Lundquist
1999-09-03  0:00     ` Kindness Robert Dewar
1999-09-03  0:00       ` Kindness Aidan Skinner
1999-09-03  0:00         ` Kindness Larry Kilgallen
1999-09-04  0:00           ` Kindness Aidan Skinner
1999-09-03  0:00         ` Kindness Marin David Condic
1999-09-06  0:00           ` Kindness Bill Findlay
1999-09-06  0:00             ` Kindness Robert Dewar
1999-09-07  0:00             ` Kindness Marin David Condic
1999-09-07  0:00               ` Kindness Bill Findlay
1999-09-06  0:00       ` Kindness Geoff Bull
1999-09-05  0:00         ` Kindness Aidan Skinner
1999-09-02  0:00 ` Kindness Larry Kilgallen
1999-09-03  0:00   ` Kindness Robert Dewar
1999-09-03  0:00     ` Kindness Andy Askey
1999-09-05  0:00       ` Kindness Robert Dewar
1999-09-07  0:00         ` Kindness Andy Askey
1999-09-07  0:00           ` Kindness Bill Findlay
1999-09-02  0:00 ` Kindness Jerry Petrey
1999-09-02  0:00   ` Kindness Nick Roberts
1999-09-03  0:00 ` Kindness Matthew Heaney
1999-09-09  0:00   ` Kindness James William Zuercher
1999-09-10  0:00     ` Kindness Robert Dewar
1999-09-10  0:00     ` Kindness Mark Lundquist
1999-09-10  0:00       ` Kindness Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox