Re: Fortran and simple tree recursion
- From: Jon Harrop <usenet@xxxxxxxxxxxxxx>
- Date: Wed, 25 May 2005 13:06:42 +0100
Michael Bader wrote:
> Jon Harrop wrote:
>>> Which seems to be exactly what I need - thanks for the suggestion.
>>> There's just no similar statement in C/C++, or, in fact, any other
>>> programming language I know ...
>>
>> The C/C++ equivalent is putting "static" before every local variable
>> definition.
>
> Not quite: I'd need a static that's static to a group of functions, and
> not only to one.
That would need to be a global static in C. It could be an outer-scope
static in C++. In OCaml (or ML) you would write something like:
let a, b, c, d =
let my_static = 1 in
let rec a = ...
and b = ...
and c = ...
and d = ... in
a, b, c, d
So there is only one "my_static" and it is local to a, b, c and d.
I use this style when memoizing a function. The hash table used to store the
memoized results is then local to the function in question but there is
only one such hash table in this scope.
>> Modern languages don't let you do this yourself because it breaks
>> modularity, concurrency, safety, determinism.
>
> Exactly :-) But still it would be very useful in my case.
Yes.
>> Instead, it is left as an
>> optimisation for the compiler to do when it can prove that there are no
>> ill effects.
>
> Which is almost impossible to grasp by a compiler - recognizing such a
> system of nested recursive calls should be quite difficult.
Essentially, tail calls are simply determined by whether or not the result
is returned immediately or used as a subexpression in further computation.
In functional languages (even impure functional languages), recursion is so
common that spotting tail recursion is almost essential. Consequently, most
such compilers spot 99% of tail calls.
--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com
.
- References:
- Fortran and simple tree recursion
- From: Michael Bader
- Re: Fortran and simple tree recursion
- From: Richard Edgar
- Re: Fortran and simple tree recursion
- From: Michael Bader
- Re: Fortran and simple tree recursion
- From: James Van Buskirk
- Re: Fortran and simple tree recursion
- From: Michael Bader
- Re: Fortran and simple tree recursion
- From: Jon Harrop
- Re: Fortran and simple tree recursion
- From: Michael Bader
- Fortran and simple tree recursion
- Prev by Date: Re: Fortran and simple tree recursion
- Next by Date: Re: Upgrades from CVF std to CVF/IVF Pro
- Previous by thread: Re: Fortran and simple tree recursion
- Next by thread: Re: Fortran and simple tree recursion
- Index(es):
Relevant Pages
|