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.

  1. Outdated egg!
  2. The cell datatype
    1. The API
      1. simple-cells
      2. cell
      3. cell?
      4. cell-of?
    2. Requires
    3. Examples
  3. Last update
  4. Author
  5. License
  6. Version History

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, initialising its content to var provided all tests succedd. Without argument returns two values, the content of the cell and the list of test predicates. With argument, replaces the cell's content with that very argument, provided all tests succead.

cell?

[procedure] (cell? xpr)

Type predicate.

cell-of?

[procedure] ((cell-of? ok?) xpr)

is xpr a cell which passes the ok? test?

Requires

simple-exceptions 0.5

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

Mar 17, 2018

Author

Juergen Lorenz

License

Copyright (c) 2017-2018, 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.3
cell-of? added
1.2.1
dependency on simple-exceptions updated
1.2
now working with simple-exceptions 0.5
1.1
cells now return old content on change
1.0
initial import