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.
TOC »
cells
This module implements the cell datatype as a closure. If this closure is called without argument, it returns the state, with one argument, it changes state. Cells can now be type-checked. For convenience, cell-ref and cell-set! syntax is provided as well.
Programming interface
cells
- cells #!optional symprocedure
documentation procedure: Without an argument shows the list of exported symbols, with a symbol argument shows the signature of this symbol.
make-cell-of
- make-cell-of #!rest predicatesprocedure
constructor. creates an empty typed cell, whose state must pass all predicate checks.
cell-of?
- cell-of? #!rest predicatesprocedure
creates a predicate, which tests if it is a cell, whose state passes the predicate checks.
cell-empty?
- cell-empty? xprprocedure
checks if xpr evaluates to an empty cell.
cell-prune!
- cell-prune! c%procedure
empties its cell argument.
make-cell
- make-cellprocedure
creates an empty untyped cell.
cell
- cell argprocedure
Creates and initializes an untyped cell.
cell?
- cell? xprprocedure
checks, if xpr evaluates to an untyped cell.
cell-ref
- cell-ref clprocedure
accessor: returns the content of cell cl.
cell-set!
- cell-set! cl valprocedure
mutator: changes the content of cell cl to val.
Usage
(use cells)
Examples
(use cells) ;;; typed cells (define c% (make-cell-of number? positive?)) ((cell-of? number? positive?) c%) ; -> #t (cell-empty? c%) ; -> #t (c% 5) (cell-empty? c%) ; -> #f (c%) ; -> 5 ((cell-of? number? positive?) c%) ; -> #t (c%) ; -> 5 ((cell-of? number? zero?) c%) ; -> #f ((cell-of? number?) c%) ; -> #t ((cell-of?) c%) ; -> #t (cell-prune! c%) (cell-empty? c%) ; -> #t (condition-case (c% -5) ((exn) #f)) ; -> #f (define d% (make-cell-of number?)) (d% -5) (d%) ; -> 5 ((cell-of? number? positive?) d%) ; -> #f ((cell-of? number?) d%) ; -> #t ;;; untyped cells (define cl (cell 5)) (cell? cl) ; -> #t (cell? 5) ; -> #f ((cell-of? number?) cl) ; -> #t ((cell-of? list?) cl) ; -> #f (cell-ref cl) ; -> 5 (cell-set! cl 50) (cell-ref cl) ; -> 50 (cell-set! cl 500) (cell-ref cl) ; -> 500 ;;; implementing a stack without any error checking (define (push st% val) (st% (cons val (st%)))) (define (top st%) (car (st%))) (define (pop st%) (st% (cdr (st%)))) (define stack (cell '())) (cell? stack) ; -> #t ((cell-of? list?) stack) ; -> #t ((cell-of? number?) stack) ; -> #f (null? (stack)) ; -> #t (push stack 5) (push stack 50) (push stack 500) (top stack) ; -> 500 (pop stack) (top stack) ; -> 50 (pop stack) (top stack) ; -> 5)
Requirements
None
Last update
Jun 21, 2015
Author
License
Copyright (c) 2011-2015, Juergen Lorenz All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Version History
- 2.1
- scope bug fixed
- 2.0
- type-checked cells added, cells implemented as closures, hence cell->closure removed
- 1.2
- cells as records, cell->closure added
- 1.1.1
- compound-test added
- 1.1
- added cells, cell-ref and cell-set!
- 1.0
- initial import