Mozart Standard Library: Functional Stacks

# Functional Stacks

Denys Duchier

module
  x-oz://system/adt/Stack.ozf

This module provides a functional implementation of stacks

## Exports

The module exports the following constructors:

`{Stack.new ?S}`
  returns a new functional stack instance `S`, currently empty
`{Stack.newFromList +L ?S}`
  returns a new functional stack instance `S` initialized with the elements of list `L`

## Instance API

Each functional stack instance `S` has the following features:

`{S.get ?V}`
  returns the next value `V` available from `S`, or raises exception `empty` if none
`{S.put +V}`
  pushes a new value `V` onto the stack
`{S.getPut ?Old +New}`
  atomically, gets the next value `Old` available from `S` and pushes the value `New`. If `S` was empty, `New` is `Old` and `S` is still empty
`{S.top ?V}`
  returns the value `V` available on top of `S` without actually removing it
`{S.toList ?L}`
  returns the list `L` of all values in `S`
`{S.toListKill ?L}`
  returns the list `L` of all values in `S` and makes `S` unusable until a subsequent `{S.reset}`.
`{S.isEmpty ?B}`
  returns true iff `S` is empty
`{S.reset}`
  discards `S`'s content and resets it to an empty stack
`{S.clone ?S2}`
  returns a new functional queue instance `S2` which is a clone of `S`