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

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

simple-cells 1.1 now accepts zero or many predicates in cell-of?

File size: 3.5 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,
33initialising its content to var provided all tests succedd.
34Without argument returns two values, the content of the cell and the
35list of test predicates.
36With argument, replaces the cell's content with that very argument,
37provided all tests succead.
38
39==== cell?
40
41<procedure>(cell? xpr)</procedure>
42
43Type predicate.
44
45==== cell-of?
46
47<procedure>((cell-of? . predicates) xpr)</procedure>
48
49is xpr a cell which passes all tests of the predicates list
50
51=== Requires
52
53simple-exceptions
54
55=== Examples
56
57<enscript highlight=scheme>
58
59(use simple-cells simple-exceptions)
60
61(define o% (cell 5 integer? odd?))
62(cell? o%) ; -> #t
63((cell-of? number?) o%) ; -> #t
64((cell-of? even?) o%) ; -> #f
65(o%) ; -> 5
66(condition-case (o% 4) ((exn arguments) #f)) ; -> #f
67(o%) ; -> 5
68(define n% (cell 4 (named-lambda (3<=? x) (<= 3 x))))
69(n%) ; -> 4
70(receive (val checks) (n%) checks) ; -> (<procedure (3<=? x)>)
71(n% 20)
72(n%) ; -> 20
73(o%) ; -> 5
74(receive (val checks) (o%) checks)
75  ; -> (<procedure (number? x)> <procedure (odd? x)>)
76
77</enscript>
78
79== Last update
80
81Nov 02, 2018
82
83== Author
84
85[[/users/juergen-lorenz|Juergen Lorenz]]
86
87== License
88
89 Copyright (c) 2017-2018, Juergen Lorenz
90 All rights reserved.
91
92 Redistribution and use in source and binary forms, with or without
93 modification, are permitted provided that the following conditions are
94 met:
95 
96 Redistributions of source code must retain the above copyright
97 notice, this list of conditions and the following disclaimer.
98 
99 Redistributions in binary form must reproduce the above copyright
100 notice, this list of conditions and the following disclaimer in the
101 documentation and/or other materials provided with the distribution.
102 Neither the name of the author nor the names of its contributors may be
103 used to endorse or promote products derived from this software without
104 specific prior written permission.
105   
106 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
107 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
108 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
109 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
110 HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
111 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
112 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
113 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
114 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
115 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
116 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
117
118== Version History
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.