source: project/wiki/eggref/4/basic-sequences @ 35851

Last change on this file since 35851 was 35851, checked in by juergen, 2 years ago

basic-sequences 2.1 docu updated

File size: 6.8 KB
Line 
1[[tags: egg]]
2[[toc:]]
3
4
5== Fundamental sequence operations
6
7This module provides the minimum necessary to handle linear container
8datatypes under a common sequence interface. It's written primary to be
9used in the bindings egg but secondary to be extendable to a
10full-fledged sequence package.
11 
12=== Documentation
13
14==== basic-sequences
15
16<procedure>(basic-sequences sym ..)</procedure>
17
18documentation procedure. Shows the exported symbols and the syntax of
19such an exported symbol, respectively.
20
21==== seq-exception
22
23<procedure>(seq-exception loc msg . args)</procedure>
24
25generates a composite condition of type (exn sequence) with location loc,
26message msg and arguments args.
27
28==== seq-ref
29
30<procedure>(seq-ref seq n)</procedure>
31
32returns the nth item of the generic sequence seq
33
34==== seq-tail
35
36<procedure>(seq-tail seq n)</procedure>
37
38returns the tail of the generic sequence seq, starting at n
39
40==== seq-car
41
42<procedure>(seq-car seq)</procedure>
43
44returns the zeroth item of the generic sequence seq
45
46==== seq-cdr
47
48<procedure>(seq-cdr seq)</procedure>
49
50returns the tail of the generic sequence seq, starting at 1
51
52==== seq?
53
54<procedure>(seq? xpr)</procedure>
55
56checks, if xpr is a sequence
57
58==== seq-null?
59
60<procedure>(seq-null? seq)</procedure>
61
62checks, if seq is empty.
63
64==== seq-random-access?
65
66<procedure>(seq-random-access? seq)</procedure>
67
68checks, if seq is randomly accessible
69
70==== seq-db
71
72<procedure>(seq-db)</procedure>
73
74shows the sequence database
75
76<procedure>(seq-db type? ref: ref tail: tail maker: maker ra?: random-access?)</procedure>
77
78adds a new custom sequence type with predicate type? and keyword
79arguments ref: tail: maker: ra?: naming procedures to be later accessed
80as seq-ref, seq-tail, seq-maker and seq-randoam-access? respectively.
81
82=== Convenience procedures
83
84==== cons*
85
86<procedure>(cons* arg ....)</procedure>
87
88iterative version of cons
89
90==== list-of
91
92<procedure>(list-of ok? ...)</procedure>
93
94returns a predicate which checks, if its argument is a list which passes
95every predicate ok? ...
96
97==== pseudo-list-of
98
99<procedure>(pseudo-list-of ok? ...)</procedure>
100
101returns a predicate which checks, if its argument is a pseudo-list,
102which passes every predicate ok? ...
103
104==== vector-of
105
106<procedure>(vector-of ok? ...)</procedure>
107
108returns a predicate which checks, if its argument is a vector which
109passes every predicate ok? ...
110
111==== tagged-vector
112
113<procedure>(tagged-vector kw arg ...)</procedure>
114
115generates a tagged vector with keyword kw and args arg ...
116
117==== tagged-vector?
118
119<procedure>(tagged-vector? xpr)</procedure>
120
121type predicate
122
123==== tagged-vector-of
124
125<procedure>(tagged-vector-of ok? ...)</procedure>
126
127generates a tagged vector predicate which checks all of its arguments
128
129==== tagged-vector-ref
130
131<procedure>(tagged-vector-ref tv k)</procedure>
132
133access to kth item of tagged vector tv
134
135==== tagged-vector-tail
136
137<procedure>(tagged-vector-tail tv k)</procedure>
138
139returns a tagged subvector of tv starting at k
140
141==== thunk
142
143<macro>(thunk xpr ....)</macro>
144
145generates a thunk with body xpr ....
146
147==== thunk?
148
149<procedure>(thunk? xpr)</procedure>
150
151checks if xpr is a thunk, i.e. a nullary procedure
152
153==== symbol-dispatcher
154
155<procedure>(symbol-dispatcher alist)</procedure>
156
157creates a documentation procedure as used in all modules
158of this library.
159
160=== Requirements
161
162simple-exceptions
163
164=== Usage
165
166<enscript highlight=scheme>
167
168(use simple-exceptions basic-sequences)
169
170</enscript>
171
172=== Examples
173
174<enscript highlight=scheme>
175
176(require-library basic-sequences simple-tests arrays)
177(import basic-sequences
178        simple-tests
179        (only arrays array array? array-ref array-tail array->list))
180
181(seq-db array? ref: array-ref tail: array-tail maker: array ra?: #t)
182(define lst '(0 1 2 3 4))
183(define pls '(0 1 2 3 . 4))
184(define vec #(0 1 2 3 4))
185(define arr (array 0 1 2 3 4))
186(define str "01234")
187(seq-ref lst 3) ;-> 3
188(seq-ref pls 3) ; -> 3
189(seq-tail pls 4) ; -> 4
190(seq-ref vec 3) ; -> 3
191(seq-ref arr 3) ; -> 3
192(seq-ref str 3) ; -> #\3
193(seq-tail lst 3) ; -> '(3 4)
194(seq-tail pls 3) ; -> '(3 . 4)
195(seq-tail vec 3) ; -> #(3 4)
196(array->list (seq-tail arr 3)) ; -> '(3 4)
197(seq-tail str 3) ; -> "34"
198(seq-null? (seq-tail lst 5)) ; -> #t
199(seq-null? (seq-tail vec 5)) ; -> #t
200(seq-null? (seq-tail arr 5)) ; -> #t
201(seq-null? (seq-tail str 5)) ; -> #t
202(seq-null? (seq-tail pls 4)) ; -> #t
203(seq? lst) ; -> #t
204(seq? pls) ; -> #t
205(seq? vec) ; -> #t
206(seq? str) ; -> #t
207(seq? arr) ; -> #t
208((seq-of integer? odd?) arr) ; -> #f
209((seq-of integer? odd?) #(1 3 5 7)) ; -> #t
210(seq-maker lst) ; -> list
211(seq-maker pls) ; -> cons*
212(seq-maker vec) ; -> vector
213(seq-random-access? arr) ; -> #t
214(seq-random-access? vec) ; -> #t
215(seq-random-access? lst) ; -> #f
216(cons* 0 1 2 3) ; -> '(0 1 2 . 3)
217(thunk? (thunk 1 2 3)) ; -> #t
218(define tv (tagged-vector x: 0 1 2 3))
219(tagged-vector-ref tv 0) ; -> x:
220(define null (tagged-vector x:))
221(tagged-vector? null) ; -> #t
222(seq? null) ; -> #t
223(seq-null? null) ; -> #f
224(define tv3 (tagged-vector-tail tv 3))
225(tagged-vector-ref tv3 0) ; -> x:
226(define tv4 (tagged-vector-tail tv 4))
227(tagged-vector? tv4) ; -> #t
228(seq-null? tv4) ; -> #f
229(define tv5 (tagged-vector-tail tv 5))
230(seq-null? tv5) ; -> #t
231(condition-case (tagged-vector-ref tv5 0)
232  ((exn sequence) #f)) ; -> #f
233
234</enscript>
235
236== Last update
237
238Jul 12, 2018
239
240== Author
241
242[[/users/juergen-lorenz|Juergen Lorenz]]
243
244== License
245
246 Copyright (c) 2011-2018, Juergen Lorenz
247 All rights reserved.
248
249 Redistribution and use in source and binary forms, with or without
250 modification, are permitted provided that the following conditions are
251 met:
252 
253 Redistributions of source code must retain the above copyright
254 notice, this list of conditions and the following disclaimer.
255 
256 Redistributions in binary form must reproduce the above copyright
257 notice, this list of conditions and the following disclaimer in the
258 documentation and/or other materials provided with the distribution.
259 Neither the name of the author nor the names of its contributors may be
260 used to endorse or promote products derived from this software without
261 specific prior written permission.
262   
263 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
264 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
265 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
266 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
267 HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
268 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
269 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
270 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
271 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
272 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
273 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274
275== Version History
276; 2.1 ; bug in tagged-vector? fixed, thanks to Martin Schneeweis
277; 2.0 ; tagged vectors added to be used with algebraic types
278; 1.0 : initial import
Note: See TracBrowser for help on using the repository browser.