<<<<<<<<<<<<<<<<<

stack(prog_tools) Programming Tools stack(prog_tools)

NAME

stack - implements stack behavior for objects or strings

DESCRIPTION

The stack object provides the classic stack semantics for objects or strings. That is, objects or strings can be placed in a list in a last in first out basis.

Since the stack object is a subclass of collection, many of the methods provided by collection are also available to stack. One major difference between collection and stack, however, is that the stack will only forward messages to the top n objects in the stack, as defined by the forward=n message (n=1 by default).

SUPERCLASS

collection

INSTANCE VARIABLES (see collection)

forward value used to indicate number of objects in the stack to forward messages to. By default forward=1 (just the top item in the stack). If forward <= 0, messages are sent to all items on the stack.

MESSAGES

push:, members+ (s1,s2,...sn) Add an object name or string onto the stack.

pop! Delete the top element from the stack.

pop? Get the value on the top of the stack, then delete it from the stack.

?, value? Obtain the top element of the stack.

forward= value Set the number of entries on the top of the stack to forward unknown messages to.

forward? Get the number of entries forwarded to.

EXAMPLE

/* * Basic stuff */ stack new: astack push:(a,b,c) print:members print:number_members

pop! print:members print:number_members ;

actor new: [astack pop?]; astack print:members print:number_members ;

actor new: astack; /* stack responds to ? or value? */ astack print:members print:number_members ;

astack members+(d,e,f) /* Note that members+ and push: are aliased */ print:members print:number_members ;

actor print:instances;

SEE ALSO

collection


Please send comments and suggestions to
consult@rpi.edu