Description

Provides FIFO queue (stack) operations.

Author

Kon Lovett

Version

Requires

Usage

(require-extension stack)

Download

stack.egg

Documentation

stack is a set of procedures and macros supporting FIFO 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)

Returns a new, empty, stack.

macro: (stack? STACK)

Returns #t for a stack STACK, #f otherwise. Not fool-proof!

macro: (stack-empty? STACK)

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

macro: (stack-length STACK)

Returns the number of elements on the stack STACK.

macro: (stack-peek STACK [INDEX])

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

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

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

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

Pushes value(s) VALUE onto the stack STACK. Returns the modified stack. The stack is modified in place.

macro: (stack-pop! STACK)

Removes the top element from the stack 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 START-DEPTH thru end-depth END-DEPTH and returns a list of the stack elements. The stack is modified in place. The start-depth must be 0 <= & <= (stack-length)-1. The end-depth must be start-depth <= & <= (stack-length)-1, defaults to start-depth.

macro: (list->stack LIST)

Returns the list 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 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 queue object and should not be modified.

macro: (stack-for-each Stack PROCEDURE)

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

macro: (print-stack STACK)

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