HP3000-L Archives

March 1998, Week 2

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Roy Brown <[log in to unmask]>
Reply To:
Roy Brown <[log in to unmask]>
Date:
Fri, 6 Mar 1998 16:08:49 +0000
Content-Type:
text/plain
Parts/Attachments:
text/plain (46 lines)
In article <[log in to unmask]>, Dan Bundus
<[log in to unmask]> writes
>Speaking of academics...
>
>As we know, truly recursive applications make use of unique
>local variable values in each recursive call; in COBOL this can
>only be accomplished with a subprogram.

Recursion is a very powerful tool, and we use it extensively. Without it, I
suspect that handling Bills of Materials would be very tiresome. But we've
never tried it within a single program, and indeed, there's no need.

Even on CM, it was quite feasible to use 100 levels of recursion if you
followed a few simple rules:
use a dynamic subprogram for the recurring element;
use the absolute minimum of working storage you could in the subprogram;
and, correspondingly, put as much as possible of what you did need in linkage.

There are three elements of storage needed in a recursion. These are:
data elements to be passed down (and back up) from the recursion;
data elements which must be preserved at each level of recursion;
'scratchpad' items needed during a level of recursion, but not for passing up
or down.

The 'must pass' items are in the block of working storage from the main
program that is passed to the subroutine;
The 'preserve at level' items are the unavoidable working storage for the
subprogram.
The 'scratchpad' items, paradoxically, are better specified in the passed
area. Seems odd at first, but that way they only occur once, rather than
however many times you have levels of recursion.

The stack consideration is then easily dealt with. As an exercise, add the
subprogram working storage to the main program, OCCURS n where n is the level
of recursion you wish to achieve, and run the main program, without the
subroutine. If it doesn't blow the stack, then it won't blow it when you
implement the recursion 'for real'.

Native Mode has rather spoiled the fun here; blowing the stack is much too
hard these days....
--
Roy Brown               Phone : (01684) 291710     Fax : (01684) 291712
Affirm Ltd              Email : [log in to unmask]
The Great Barn, Mill St         Programmer's Encyclopaedia definition -
TEWKESBURY GL20 5SB (UK)        'Recursion': see 'Recursion'

ATOM RSS1 RSS2