The cell datatype
In their paper "The First Report on Scheme Revisited", the authors Sussman and Steele remarked
"We also now believe that Carl Hewitt was right: we would have been better off to have introduced cells as a separate, primitive kind of object, rather than allowing assignment to any and every lambda-bound variable."
This module implements the cell datatype as a procedure of zero or one argument. Using it instead of set! set-car! and set-cdr! you have what Hewitt proposed ...
The API
simple-cells
[procedure] (simple-cells sym ..)Documentation procedure. Without argument, returns the list of exported symbols, with argument the documentation of that symbol.
cell
[procedure] (cell var . tests)Constructor. Creates a cell as a procedure of zero or one argument, closed over its state and initializes that state with var provided all tests succedd. Called without argument the cell returns its state, with argument, replaces the cell's state with that very argument and returns the old state, provided all tests succead.
cell?
[procedure] (cell? xpr)Type predicate.
cell-of?
[procedure] ((cell-of? . predicates) xpr)is xpr a cell which passes all tests of the predicates list
Requires
simple-exceptions
Examples
(use simple-cells simple-exceptions) (define o% (cell 5 integer? odd?)) (cell? o%) ; -> #t ((cell-of? number?) o%) ; -> #t ((cell-of? even?) o%) ; -> #f (o%) ; -> 5 (condition-case (o% 4) ((exn arguments) #f)) ; -> #f (o%) ; -> 5 (define n% (cell 4 (named-lambda (3<=? x) (<= 3 x)))) (n%) ; -> 4 (receive (val checks) (n%) checks) ; -> (<procedure (3<=? x)>) (n% 20) (n%) ; -> 20 (o%) ; -> 5 (receive (val checks) (o%) checks) ; -> (<procedure (number? x)> <procedure (odd? x)>)
Last update
Feb 02, 2019
Author
Repository
This egg is hosted on the CHICKEN Subversion repository:
https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/simple-cells
If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.
License
Copyright (c) 2017-2019, 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
- 1.2
- dependency on simple-exceptions changed to that on checks
- 1.1.1
- synchronizes documentation with code
- 1.1
- cell-of? now accepts zero or many predicates
- 1.0
- ported from chicken-4 version 1.3 with modification