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 ...
- simple-cells sym ..procedure
Documentation procedure. Without argument, returns the list of exported symbols, with argument the documentation of that symbol.
- cell var #!rest testsprocedure
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? xprprocedure
(use simple-cells simple-exceptions) (define o% (cell 5 number? odd?)) (cell? o%) ; -> #t (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)>)
Feb 17, 2017
Copyright (c) 2017, 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.
- dependency on simple-exceptions updated
- now working with simple-exceptions 0.5
- cells now return old content on change
- initial import