source: project/wiki/eggref/5/simple-cells @ 36760

Last change on this file since 36760 was 36760, checked in by juergen, 6 months ago

simple-cells 1.1.1 synchronizes documentation with code

File size: 3.6 KB
Line 
1[[tags: egg]]
2[[toc:]]
3
4
5== The cell datatype
6
7In their paper "The First Report on Scheme Revisited", the authors
8Sussman and Steele remarked
9
10"We also now believe that Carl Hewitt was right: we would have been
11better off to have introduced cells as a separate, primitive kind of
12object, rather than allowing assignment to any and every lambda-bound
13variable."
14
15This module implements the cell datatype as a procedure of zero or one
16argument. Using it instead of set!  set-car! and set-cdr! you have
17what Hewitt proposed ...
18
19=== The API
20
21==== simple-cells
22
23<procedure>(simple-cells sym ..)</procedure>
24
25Documentation procedure. Without argument, returns the list of exported
26symbols, with argument the documentation of that symbol.
27
28==== cell
29
30<procedure>(cell var . tests)</procedure>
31
32Constructor. Creates a cell as a procedure of zero or one argument,
33closed over its state and initializes that state with var provided all
34tests succedd.  Called without argument the cell returns its state, with
35argument, replaces the cell's state with that very argument and returns
36the old state, provided all tests succead.
37
38==== cell?
39
40<procedure>(cell? xpr)</procedure>
41
42Type predicate.
43
44==== cell-of?
45
46<procedure>((cell-of? . predicates) xpr)</procedure>
47
48is xpr a cell which passes all tests of the predicates list
49
50=== Requires
51
52simple-exceptions
53
54=== Examples
55
56<enscript highlight=scheme>
57
58(use simple-cells simple-exceptions)
59
60(define o% (cell 5 integer? odd?))
61(cell? o%) ; -> #t
62((cell-of? number?) o%) ; -> #t
63((cell-of? even?) o%) ; -> #f
64(o%) ; -> 5
65(condition-case (o% 4) ((exn arguments) #f)) ; -> #f
66(o%) ; -> 5
67(define n% (cell 4 (named-lambda (3<=? x) (<= 3 x))))
68(n%) ; -> 4
69(receive (val checks) (n%) checks) ; -> (<procedure (3<=? x)>)
70(n% 20)
71(n%) ; -> 20
72(o%) ; -> 5
73(receive (val checks) (o%) checks)
74  ; -> (<procedure (number? x)> <procedure (odd? x)>)
75
76</enscript>
77
78== Last update
79
80Nov 05, 2018
81
82== Author
83
84[[/users/juergen-lorenz|Juergen Lorenz]]
85
86== License
87
88 Copyright (c) 2017-2018, Juergen Lorenz
89 All rights reserved.
90
91 Redistribution and use in source and binary forms, with or without
92 modification, are permitted provided that the following conditions are
93 met:
94 
95 Redistributions of source code must retain the above copyright
96 notice, this list of conditions and the following disclaimer.
97 
98 Redistributions in binary form must reproduce the above copyright
99 notice, this list of conditions and the following disclaimer in the
100 documentation and/or other materials provided with the distribution.
101 Neither the name of the author nor the names of its contributors may be
102 used to endorse or promote products derived from this software without
103 specific prior written permission.
104   
105 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
106 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
107 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
108 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
109 HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
110 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
111 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
112 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
113 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
114 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
115 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
116
117== Version History
118; 1.1.1 : synchronizes documentation with code
119; 1.1 : cell-of? now accepts zero or many predicates
120; 1.0 : ported from chicken-4 version 1.3 with modification
Note: See TracBrowser for help on using the repository browser.