Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

stack

  1. Outdated egg!
  2. stack
  3. Documentation
    1. make-stack
    2. list->stack
    3. stack?
    4. stack-empty?
    5. stack-count
    6. stack-empty!
    7. stack-peek
    8. stack-poke!
    9. stack-push!
    10. stack-pop!
    11. stack-cut!
    12. stack->list
    13. stack-fold
    14. stack-for-each
    15. stack-map
  4. Usage
  5. Examples
  6. Notes
  7. Requirements
  8. Bugs and Limitations
  9. Author
  10. Version history
  11. License

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

setup-helper check-errors

Bugs and Limitations

Author

Kon Lovett

Version history

2.3.0
Drop typed-modules.
2.2.1
Fix type.
2.2.0
Uses typed-modules egg. Slightly faster.
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-2017 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.