From: glen herrmannsfeldt on
Richard Maine <nospam(a)see.signature> wrote:
(snip)

> I repeat my statement that I would only do it if it were affirmatively
> documented to be supported. No you cannot just trust that it will work
> if it is not documented to. That was my whole point. Just trusting that
> it will work is the opposite of my recommendation.

Well, you could also read the compiler source code and see
what it does...

> If it is an f90+ compiler and you use the recursive keyword, then it is
> documented to work. That documentation is the f90 standard, in
> conjunction with the compiler's claim to be an f90 compiler.

> Do note the condition about using the recursive keyword. That keyword
> was added to the language for a reason - not just to trip up users. The
> reason is that support of recursion might require extra overhead in some
> cases. Therefore, by telling the compiler which procedures need to work
> recursively, the compiler can make those procedures work without
> burdening every procedure in every program with the generally unneeded
> overhead.

Since C doesn't require a special keyword, and many Fortran
compiler code generators are based on C compiler code, there
is a good chance that newer Fortran compilers generate the
same code in any case. Still, don't count on it.

> So no, you can't count of recursion to work without the recursive
> keyword. I think that's what you were asking.

> If you end up accidentally making an indirect recursive call to a
> non-recursive procedure, that's a program bug, and unfortunately one
> that might well pass your testing but give wrong answers when it
> actually matters.

In addition, you must make sure that your code is properly recursive.
The use of static variables, for example, can cause it to fail.

-- glen

From: Phred Phungus on
glen herrmannsfeldt wrote:

> In the Fortran 66 days, (I believe 1977) for testing purposes
> I wrote a recursive function for TOPS-10 Fortran-10. That
> compiler keeps the return address on the stack, but local variables
> are static. To get around that, I used an array for local varaibles,
> and incremented/decremented a variable with recursion depth.
> This was recently discussed on the alt.sys.pdp10 newsgroup!
> (There is a PDP-10 system run by PDPplanet that one can test
> out such code on.) In that case, because of the local variable
> problem, a wrapper function was needed.

Why can't I emulate a pdp on ubuntu, other than not having any idea how
to do so?
--
fred
From: Richard Maine on
glen herrmannsfeldt <gah(a)ugcs.caltech.edu> wrote:

> I think this means
> that RESULT is needed for recursive functions that directly
> call themselves, but I don't see the words in the standard
> that say so.

They are there - just from a different direction than you are looking.

F2003 (and there is simillar wording in other versions)

"If RESULT is not specified, the result variable is <function-name>
and all occurences of <function-name> in the execution-part statements
in the scoping unit are references to the result variable."

That means there isn't any way to write a direct recursive call in that
case because you would need to have <function-name> be interpreted as
other than the result variable.

P.S. I notice an infelicity on the above wording in the standard.
Whoever wrote it forgot about the definition of "reference" in the
Fortran standard. When you write, for instance

<function-name> = some-expression

as you need to do in a function, that is not a reference to
<function-name>. The standard should undoubtedly use one of the wording
variants that don't contradict the definition of "reference". One such
variant is to say that they "refer to" instead of "are references to".

I don't suppose anyone still on the committee wants to add this to the
list of minor errata?

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
From: glen herrmannsfeldt on
Phred Phungus <Phred(a)example.invalid> wrote:

> Why can't I emulate a pdp on ubuntu, other than not having
> any idea how to do so?

You can do that, but you can also get free accounts
on PDPplanet.

-- glen
From: ajay on
On Mar 26, 9:34 am, glen herrmannsfeldt <g...(a)ugcs.caltech.edu> wrote:
> Phred Phungus <Ph...(a)example.invalid> wrote:
> > Why can't I emulate a pdp on ubuntu, other than not having
> > any idea how to do so?
>
> You can do that, but you can also get free accounts
> on PDPplanet.
>
> -- glen

I came across very intersting example from : http://www.esm.psu.edu/~ajm138/fortranexamples.html

PROGRAM MAIN
INTEGER N, X
EXTERNAL SUB1
COMMON /GLOBALS/ N
X = 0
PRINT *, 'Enter number of repeats'
READ (*,*) N
CALL SUB1(X,SUB1)
END

SUBROUTINE SUB1(X,DUMSUB)
INTEGER N, X
EXTERNAL DUMSUB
COMMON /GLOBALS/ N
IF(X .LT. N)THEN
X = X + 1
PRINT *, 'x = ', X
CALL DUMSUB(X,DUMSUB)
END IF
END