You are looking at historical revision 28426 of this page. It may differ significantly from its current revision.

stack

Documentation

The stack extension is a set of procedures and macros supporting LIFO queue operations.

make-stack

[procedure] (make-stack) => STACK

Returns a new STACK object.

list->stack

[procedure] (list->stack LIST) => STACK

Returns a new STACK object with initial elements from the LIST.

The stack order is as (apply stack-push! STACK (reverse LIST)). In other words LIST should be in the desired LIFO order.

stack?

[procedure] (stack? OBJECT) => BOOLEAN

Is OBJECT a stack?

stack-empty?

[procedure] (stack-empty? STACK) => BOOLEAN

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

stack-count

[procedure] (stack-count STACK) => NUMBER

Returns the count of elements on the STACK.

stack-empty!

[procedure] (stack-empty! STACK)

Make STACK empty.

stack-peek

[procedure] (stack-peek STACK [INDEX]) => OBJECT

Returns the element in STACK at INDEX.

INDEX must be in [0 (stack-count) - 1]. INDEX defaults to 0.

stack-poke!

[procedure] (stack-poke! STACK OBJECT [INDEX])

Changes the STACK element at INDEX to OBJECT.

INDEX must be in [0 (stack-count) - 1]. INDEX defaults to 0.

The stack is modified in place.

stack-push!

[procedure] (stack-push! STACK OBJECT ...)

Pushes OBJECT ... onto the STACK.

The stack is modified in place.

stack-pop!

[procedure] (stack-pop! STACK) => OBJECT

Removes the top element from the STACK and returns it.

The stack is modified in place.

stack-cut!

[procedure] (stack-cut! STACK START [END]) => LIST

Removes the STACK elements from the indexes START upto END and returns a list of the stack elements.

The START must be in [0 (stack-count) - 1].

The END must be in [START (stack-count)]. END defaults to (stack-count).

The stack is modified in place.

stack->list

[procedure] (stack->list STACK) => LIST

Returns the STACK as a new list, where the first element of the list is the top element of the stack.

stack-fold

[procedure] (stack-fold STACK PROCEDURE INITIAL) => OBJECT

Invokes the PROCEDURE on each element of the STACK and the accumulated result. Returns the accumulated result. The initial accumulated result is INITIAL.

Processing of the STACK elements in order of top to bottom.

stack-for-each

[procedure] (stack-for-each STACK PROCEDURE)

Invokes the PROCEDURE on each element of the STACK.

Processing of the STACK elements in order of top to bottom.

stack-map

[procedure] (stack-map STACK PROCEDURE) => LIST

Invokes the PROCEDURE on each element of the STACK, collecting in a result LIST.

Processing of the STACK elements in order of top to bottom.

Usage

(require-extension stack)

or

(require-library stack)
...
(import stack)

Examples

Notes

Requirements

Bugs and Limitations

Author

Kon Lovett

Version history

2.1.4
Fix for ticket #630.
2.1.3
2.1.2
2.1.1
2.1.0
2.0.0
Port to hygienic Chicken.

License

Copyright (C) 2009 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.