MAINFRAME > Tips & Techniques > Application Development

REXX Programmers Shouldn’t Overlook ‘Stacks’


Frequently, when writing a program, having some temporary storage space available is quite useful. Simply called “variables,” these temporary storage spaces are often assigned a name that, hopefully, indicates something meaningful related to their intended use. Doing so is considered polite, as a programmer, to try and ease the burden for those who might have to maintain code in future. You never know, it might be you one day looking at 10-year-old code you wrote, and wondering what on earth you had in mind at the time.

Variables are fine for storing a value once and retrieving it later, but what if you don’t know in advance how many items you will be asked to store? Sure, you could just keep creating new variables, but there’s a simpler way—the “stack.” Stacks are a basic programming construct that seem less well regarded in these days of object-oriented coding because it’s just as simple to instantiate another copy of a variable. However, a stack, by design, incorporates some useful characteristics your program might want to leverage.

To picture a stack, imagine a pile of dinner plates at a buffet. Generally, you take the top plate, and the next one will then be available for whomever follows you in the queue. Similarly, when workers want to replenish the stack of plates, they add a few to the top of the stack, pushing those that were previously at the top down a few places. If you can picture this concept, then you understand the stack—each plate represents a variable containing an arbitrary value assigned it before it was placed on top of the stack.

There's one important detail, though, that this analogy doesn’t quite convey: In a programming environment, it's usually possible to grab a plate from the bottom of the stack, just as readily as from the top. Likewise, you can add a plate to the bottom.

Stacks that allow access from only the top are called last in, first out (LIFO) stacks, whereas those that work from the bottom are first in, first out (FIFO) stacks. In REXX, you can access a stack in either way through a variety of instructions.

To see examples of both methods of stack manipulation, copy the code example here into your exec library and execute it. The sample program takes two arguments: the first indicates the number of stacks being creating, then a YES/NO indication of whether to clear the stacks each time. The second sample shows why you would want the option of clearing the stacks or not.

Michael Cairns works for IBM as a technical specialist in the Tivoli zSecure range of software. Michael can be reached at mike.cairns@au1.ibm.com.


comments powered by Disqus

Advertisement

Advertisement

2019 Solutions Edition

A Comprehensive Online Buyer's Guide to Solutions, Services and Education.

A Beginner's Guide to the REXX Programming Language on z/OS

Reading and Writing Files in the REXX programming language on z/OS.

MAINFRAME > TIPS & TECHNIQUES > APPLICATION DEVELOPMENT

Application Management is Important to the Entire Process

MAINFRAME > TIPS & TECHNIQUES > APPLICATION DEVELOPMENT

Application Testing: Giving Users What They Need

IBM Systems Magazine Subscribe Box Read Now Link Subscribe Now Link iPad App Google Play Store
Mainframe News Sign Up Today! Past News Letters