From: Nicolas Neuss on
"Chuck Stevens" <charles.stevens(a)unisys.com> writes:

> Hmmm. I don't have any problem with the following program using either of
> the COBOL compilers supported for the Unisys MCP systems ('74 and '85
> standards respectively):
>
> IDENTIFICATION DIVISION.
> ENVIRONMENT DIVISION.
> DATA DIVISION.
> WORKING-STORAGE SECTION.
> 77 FACT-RES PIC 9(8).
> 77 ARGUMENT PIC 9(8).
> PROCEDURE DIVISION.
> MAIN-LINE.
> MOVE 1 TO FACT-RES. MOVE 5 TO ARGUMENT.
> PERFORM COMPUTE-FACTORIAL.
> DISPLAY FACT-RES.
> STOP RUN.
> COMPUTE-FACTORIAL.
> IF ARGUMENT > 1
> COMPUTE FACT-RES = FACT-RES * ARGUMENT
> SUBTRACT 1 FROM ARGUMENT
> PERFORM COMPUTE-FACTORIAL.

OK, this works for me (OpenCobol) after indenting by 8 and introducing a
line 2
PROGRAM-ID. FACTORIAL.

Thanks, Nicolas.
From: Oliver Wong on

"Chuck Stevens" <charles.stevens(a)unisys.com> wrote in message
news:dq0k3c$2dsd$1(a)si05.rsvl.unisys.com...
>
> Can you cite some documentation somewhere supporting the assertion that
> one can't PERFORM a paragraph from within the paragraph (whether or not
> that paragraph is also PERFORMed externally)?

http://www.csis.ul.ie/COBOL/Course/Iteration.htm
<quote>
Although Netexpress does allow recursive Performs, this is a nonstandard
extension. Please do not take advantage of it..
</quote>
<quote>
Recursion not allowed.
Although Performs can be nested, neither direct nor indirect recursion is
allowed. This means that a paragraph must not contain a PERFORM that invokes
itself or any ancestor paragraph (parent, grandparent etc). Unfortunately
this restriction is not enforced by the compiler but your program will not
work correctly if you use recursive Performs
</quote>

http://docs.hp.com/cgi-bin/doc3k/B3150090014.11950/16
<quote>
Do not write an illegal program, even if it works on the first
machine for which you are writing the program. It may not work
the same way on another machine. (Examples of illegal things that
may work differently on different machines are: branching out of
PERFORM paragraphs, PERFORM statements with common exit points,
and indirectly recursive PERFORM statements.)
</quote>

My understanding of the behaviour of the PERFORM statement, though I
cannot currently find documentation to back this up, is that there is no
"call stack". Rather, each paragraph has a memory slot associated to it in
which it stores the return address, so if a paragraph calls itself (directly
or indirectly), one of the return addresses will get overwritten and thus
lost.

- Oliver


From: Chuck Stevens on
Thanks for pointing out the additional requirement. I'd forgotten that
PROGRAM-ID was (and has apparently always been) required by the standard,
and that our relaxation of that rule was an implementor-defined extension.

The Unisys MCP COBOLs before '85 don't require PROGRAM-ID at all, and the
'85 implementation doesn't require it for simple monolithic standalone
programs, only for programs that are nested or that contain nested programs,
and for sequences of monolithic programs in a single source file compiled
into individual object code files by a single execution of the compiler.

-Chuck Stevens

"Nicolas Neuss" <Nicolas.Neuss(a)iwr.uni-heidelberg.de> wrote in message
news:87vews2h70.fsf(a)ortler.iwr.uni-heidelberg.de...
> "Chuck Stevens" <charles.stevens(a)unisys.com> writes:
>
>> Hmmm. I don't have any problem with the following program using either
>> of
>> the COBOL compilers supported for the Unisys MCP systems ('74 and '85
>> standards respectively):
>>
>> IDENTIFICATION DIVISION.
>> ENVIRONMENT DIVISION.
>> DATA DIVISION.
>> WORKING-STORAGE SECTION.
>> 77 FACT-RES PIC 9(8).
>> 77 ARGUMENT PIC 9(8).
>> PROCEDURE DIVISION.
>> MAIN-LINE.
>> MOVE 1 TO FACT-RES. MOVE 5 TO ARGUMENT.
>> PERFORM COMPUTE-FACTORIAL.
>> DISPLAY FACT-RES.
>> STOP RUN.
>> COMPUTE-FACTORIAL.
>> IF ARGUMENT > 1
>> COMPUTE FACT-RES = FACT-RES * ARGUMENT
>> SUBTRACT 1 FROM ARGUMENT
>> PERFORM COMPUTE-FACTORIAL.
>
> OK, this works for me (OpenCobol) after indenting by 8 and introducing a
> line 2
> PROGRAM-ID. FACTORIAL.
>
> Thanks, Nicolas.


From: Peter Lacey on
Alain Reymond wrote:
>
> Nicolas,
>
> Try to use the recursive posssibilities of modern Cobol. This is good
> for teaching and showing that Cobol is no more an amount of go to's in
> spaghetti code (troll)...
>
Why teach the more complicated method first? This isn't a case where
using recursion is preferable. Also (troll-reply) an instructor
shouldn't get involved in religious wars unless that happens to be the
course subject.

PL
From: charles hottel on

"Chuck Stevens" <charles.stevens(a)unisys.com> wrote in message
news:dq0k3c$2dsd$1(a)si05.rsvl.unisys.com...
>
> "charles hottel" <jghottel(a)yahoo.com> wrote in message
> news:a9c14$43c31f96$4f9c6e7$32726(a)DIALUPUSA.NET...
>>
>> "Nicolas Neuss" <firstname.lastname(a)iwr.uni-heidelberg.de> wrote in
>> message news:87lkxpgnwc.fsf(a)ortler.iwr.uni-heidelberg.de...
>>
>> <snip>
>>
>>> I had found this one already, but had somehow hoped that a nicer version
>>> would be possible, e.g. something like in
>>>
>>> <http://groups.google.com/group/comp.lang.cobol/msg/fae713b0615c1445>
>>>
>>> Thank you,
>>>
>>> Nicolas.
>>
>> I do not think that the program at this link is valid COBOL. A COBOL
>> program can be recursive but COBOL paragraphs are not recursive at least
>> not in the compilers that I am familiar with.
>
> Hmmm. I don't have any problem with the following program using either of
> the COBOL compilers supported for the Unisys MCP systems ('74 and '85
> standards respectively):
>
> IDENTIFICATION DIVISION.
> ENVIRONMENT DIVISION.
> DATA DIVISION.
> WORKING-STORAGE SECTION.
> 77 FACT-RES PIC 9(8).
> 77 ARGUMENT PIC 9(8).
> PROCEDURE DIVISION.
> MAIN-LINE.
> MOVE 1 TO FACT-RES. MOVE 5 TO ARGUMENT.
> PERFORM COMPUTE-FACTORIAL.
> DISPLAY FACT-RES.
> STOP RUN.
> COMPUTE-FACTORIAL.
> IF ARGUMENT > 1
> COMPUTE FACT-RES = FACT-RES * ARGUMENT
> SUBTRACT 1 FROM ARGUMENT
> PERFORM COMPUTE-FACTORIAL.
>
> I've looked at the standards, and don't see anything that says PERFORMing
> a paragraph recursively is illegal (though a STACK OVERFLOW fault in a
> COBOL program on Unisys MCP systems is virtually diagnostic of
> re-executing a PERFORM without ever completing the PERORM range it is in,
> so such matters must be handled with care).
>
> Can you cite some documentation somewhere supporting the assertion that
> one can't PERFORM a paragraph from within the paragraph (whether or not
> that paragraph is also PERFORMed externally)?
>
> -Chuck Stevens
>

Well I remember trying it with IBM mainframe COBOL and IIRC it resulted in
an infinite loop.


First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9 10
Prev: Data Representation in COBOL
Next: xml acucobol