((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/cells" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.") (tags "egg") (toc)) (section 2 "cells" (p "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.") (section 3 "Programming interface" (section 4 "cells" (def (sig (procedure "(cells [sym])" (id cells))) (p "documentation procedure: Without an argument shows the list of exported symbols, with a symbol argument shows the signature of this symbol."))) (section 4 "make-cell-of" (def (sig (procedure "(make-cell-of . predicates)" (id make-cell-of))) (p "constructor. creates an empty typed cell, whose state must pass all predicate checks."))) (section 4 "cell-of?" (def (sig (procedure "(cell-of? . predicates)" (id cell-of?))) (p "creates a predicate, which tests if it is a cell, whose state passes the predicate checks."))) (section 4 "cell-empty?" (def (sig (procedure "(cell-empty? xpr)" (id cell-empty?))) (p "checks if xpr evaluates to an empty cell."))) (section 4 "cell-prune!" (def (sig (procedure "(cell-prune! c%)" (id cell-prune!))) (p "empties its cell argument."))) (section 4 "make-cell" (def (sig (procedure "(make-cell)" (id make-cell))) (p "creates an empty untyped cell."))) (section 4 "cell" (def (sig (procedure "(cell arg)" (id cell))) (p "Creates and initializes an untyped cell."))) (section 4 "cell?" (def (sig (procedure "(cell? xpr)" (id cell?))) (p "checks, if xpr evaluates to an untyped cell."))) (section 4 "cell-ref" (def (sig (procedure "(cell-ref cl)" (id cell-ref))) (p "accessor: returns the content of cell cl."))) (section 4 "cell-set!" (def (sig (procedure "(cell-set! cl val)" (id cell-set!))) (p "mutator: changes the content of cell cl to val.")))) (section 3 "Usage" (highlight scheme "(use cells)")) (section 3 "Examples" (highlight scheme "(use cells)\n\n;;; typed cells\n(define c% (make-cell-of number? positive?))\n((cell-of? number? positive?) c%) ; -> #t\n(cell-empty? c%) ; -> #t\n(c% 5)\n(cell-empty? c%) ; -> #f\n(c%) ; -> 5\n((cell-of? number? positive?) c%) ; -> #t\n(c%) ; -> 5\n((cell-of? number? zero?) c%) ; -> #f\n((cell-of? number?) c%) ; -> #t\n((cell-of?) c%) ; -> #t\n(cell-prune! c%)\n(cell-empty? c%) ; -> #t\n(condition-case (c% -5)\n  ((exn) #f)) ; -> #f\n(define d% (make-cell-of number?))\n(d% -5)\n(d%) ; -> 5\n((cell-of? number? positive?) d%) ; -> #f\n((cell-of? number?) d%) ; -> #t\n\n;;; untyped cells\n(define cl (cell 5))\n(cell? cl) ; -> #t\n(cell? 5) ; -> #f\n((cell-of? number?) cl) ; -> #t\n((cell-of? list?) cl) ; -> #f\n(cell-ref cl) ; -> 5\n(cell-set! cl 50)\n(cell-ref cl) ; -> 50\n(cell-set! cl 500)\n(cell-ref cl) ; -> 500\n\n;;; implementing a stack without any error checking\n(define (push st% val)\n  (st% (cons val (st%))))\n(define (top st%)\n  (car (st%)))\n(define (pop st%)\n  (st% (cdr (st%))))\n\n(define stack (cell '()))\n(cell? stack) ; -> #t\n((cell-of? list?) stack) ; -> #t\n((cell-of? number?) stack) ; -> #f\n(null? (stack)) ; -> #t\n(push stack 5)\n(push stack 50)\n(push stack 500)\n(top stack) ; -> 500\n(pop stack)\n(top stack) ; -> 50 \n(pop stack)\n(top stack) ; -> 5)\n")) (section 3 "Requirements" (p "None"))) (section 2 "Last update" (p "Jun 21, 2015")) (section 2 "Author" (p (int-link "/users/juergen-lorenz" "Juergen Lorenz"))) (section 2 "License" (pre "Copyright (c) 2011-2015, Juergen Lorenz\nAll rights reserved.") (pre "Redistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\nRedistributions of source code must retain the above copyright\nnotice, this list of conditions and the following disclaimer.\n\nRedistributions in binary form must reproduce the above copyright\nnotice, this list of conditions and the following disclaimer in the\ndocumentation and/or other materials provided with the distribution.\nNeither the name of the author nor the names of its contributors may be\nused to endorse or promote products derived from this software without\nspecific prior written permission. \n  \nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS\nIS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\nTO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\nPARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nHOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED\nTO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR\nPROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\nLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\nNEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\nSOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.")) (section 2 "Version History" (dl (dt "2.1") (dd "scope bug fixed") (dt "2.0") (dd "type-checked cells added, cells implemented as closures, hence cell->closure removed") (dt "1.2") (dd "cells as records, cell->closure added") (dt "1.1.1") (dd "compound-test added") (dt "1.1") (dd "added cells, cell-ref and cell-set!") (dt "1.0") (dd "initial import"))))