Description

Provides LIFO queue (stack) operations.

Author

Kon Lovett

Version

Usage

(require-extension stack)

Download

stack.egg

Documentation

stack is a set of procedures and macros supporting LIFO queue operations. The stack is treated as an independent object, which is modified in place. In opposition to the common pattern of a variable being re-assinged a new stack representation after each mutating operation.

macro: (make-stack [LIST])

Returns a new stack, with optional initial elements from LIST.

macro: (clear-stack STACK)

Make STACK empty.

macro: (stack? STACK)

Is STACK a stack?

macro: (stack-empty? STACK)

Returns #t for an empty STACK, #f otherwise.

macro: (stack-length STACK)

Returns the number of elements on the STACK.

macro: (stack-depth STACK)

Returns the index of the last element on the STACK, or -1 when stack empty.

macro: (stack-peek STACK [INDEX])

Returns the element in STACK at INDEX. Index must be 0 <= & <= (stack-depth), defaults to 0 (top of stack).

macro: (stack-poke! STACK VALUE [INDEX])

Changes the STACK element at INDEX to VALUE. Returns the modified stack. The stack is modified in place. Index must be 0 <= & <= (stack-depth), defaults to 0 (top of stack).

macro: (stack-push! STACK VALUE ...)

Pushes VALUE ... onto the STACK. Returns the modified stack. The stack is modified in place.

macro: (stack-pop*! STACK)

Removes the top element from the STACK and returns it. The stack is modified in place. Does not check for the stack-empty condition!

procedure: (stack-pop! STACK)

Removes the top element from the STACK and returns it. The stack is modified in place.

procedure: (stack-cut! STACK START-DEPTH [END-DEPTH])

Removes the STACK elements from START-DEPTH thru END-DEPTH and returns a list of the stack elements. The stack is modified in place. The start-depth must be 0 <= & <= (stack-depth). The end-depth must be start-depth <= & <= (stack-depth), defaults to start-depth.

macro: (list->stack LIST)

Returns the LIST as a stack. The resulting stack may share memory with the list and the list should not be modified after this operation.

macro: (stack->list STACK)

Returns the STACK as a list, where the first element of the list is the top element of the stack. The resulting list may share memory with the stack object and should not be modified.

macro: (stack-for-each STACK PROCEDURE)

Applies the PROCEDURE to each element of the STACK, in order of top to bottom.

macro: (print-stack STACK)

Prints the elements of the STACK to the (current-output-port).

License

Copyright (c) 2005, Kon Lovett.  All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the Software),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.