This page uses CSS, and renders properly in the latest versions of Microsoft Internet Explorer and Mozilla.
This is Frontier: The Definitive Guide by Matt Neuburg, unabridged and unaltered from the January 1998 printing.
It deals with the freeware Frontier 4.2.3; for commercial Frontier 8, look here, and for the inexpensive Radio UserLand, look here. See my Web site for information.
Those wishing an offline or printed copy may purchase the book, which is still in print.
Copyright 1998 O'Reilly & Associates, Inc. ALL RIGHTS RESERVED. Reprinted with permission.
TOP UP: Data Manipulation NEXT: Extending the Language

22

Stacks

A stack is a last-in-first-out storage structure, like a pile of plates: one can put a new plate on top at any time, and whenever one reaches to retrieve a plate from the top of the pile it is always the one most recently added to the pile. UserTalk implements stacks with utility scripts; they are at suites.stacks , and are worth studying, as they might give you ideas for implementing similar storage structures, such as queues.

To make a new stack:

addrMyStack = stack.create ()

The variable on the left of the assignment can be anything; the point is to capture the value of stack.create(), because this is the address of your new stack, and is needed as a parameter to the other stack verbs.

To add a value to a stack:

stack.push (addrMyStack, theValue)

To remove a value from a stack:

stack.pop (addrMyStack)

The most recently pushed value is removed from the stack, and returned as the value of the verb call. If the stack is empty, a runtime error is generated; you can handle this gracefully by embedding the call in a try...else structure.

To learn the number of elements on a stack, get its top. For instance, if we have captured the stack's address as addrMyStack, then addrMyStack^.top is the number of elements of the stack.

To examine the n th element on a stack, where the first element is the one first pushed onto the stack, say this:

addrMyStack.vals.["item" + n]

When you are done using a stack, you should dispose of it or it will remain in the database. Simply say:

stack.dispose (addrmyStack)

The verb stack.visit() is discussed Chapter 12, Control Structures.


TOP UP: Data Manipulation NEXT: Extending the Language

This is Frontier: The Definitive Guide by Matt Neuburg, unabridged and unaltered from the January 1998 printing.
It deals with the freeware Frontier 4.2.3; for commercial Frontier 8, look here, and for the inexpensive Radio UserLand, look here. See my Web site for information.
Those wishing an offline or printed copy may purchase the book, which is still in print.
Copyright 1998 O'Reilly & Associates, Inc. ALL RIGHTS RESERVED. Reprinted with permission.