source: project/wiki/eggref/5/biglists @ 37379

Last change on this file since 37379 was 37379, checked in by juergen, 21 months ago

biglists docu added

File size: 6.5 KB
Line 
1[[tags: egg]]
2[[toc:]]
3
4== Eager and lazy lists united
5
6This is an attempt to unify eager and lazy list. To use this egg you
7should carefully note the following
8
9=== Rationale
10
11* All routines start uppercase.
12
13Hence they don't interfere with ordinary list routines.
14
15* The order of arguments is consistent.
16
17Procedure arguments first, list arguments last.
18For example, there is no List-ref routine, use At instead.
19
20* Most routines are defined in curried and uncurried form.
21
22So, curried versions can be used in Map and friends.
23The documentation shows both signatures, but explains only the
24uncurried form.
25
26* Biglists are either eager or lazy.
27
28* Lazy biglists are either finite or infinite.
29
30* All biglists are basically constructed with the macro Cons:
31
32This macro has two arguments for eager biglists, and an additional third
33argument, finite?, for lazy biglists.
34
35* The empty lazy biglist, nil, is an infinite sequence of eos objects.
36
37Hence At can access even finite biglists at any position, it would
38simply return eos past the length of finite biglists.
39
40* The emppy eager biglist is '(), as usual.
41
42But to be consistent with the point above, there are no Car and Cdr
43routines, but First and Rest instead, which behave differently:
44First returns eos at the empty biglist, and Rest returns itself at the
45empty biglist.
46
47* Pattern matching on biglists is available via the bindings egg.
48
49To achieve that, bind-seq-db is already updated.
50
51* List comprehensions work as well for biglists.
52
53This is provided by the For macro.
54
55=== Documentation
56
57At present, except the documentation procedure, biglists, this file only
58lists the names of the exported symbols. There documentation can be
59shown offline with (biglists sym).
60
61Offline documentation is provided in all of my eggs.
62
63==== biglists
64
65<procedure>(biglists)</procedure>
66<procedure>(biglists sym)</procedure>
67
68The first call returns the list of exported symbols, the second
69documentation for the exported symbol sym. But note, that only the
70uncurried version is explained, while both signatures are noted.
71
72==== Append
73
74==== Assoc
75
76==== Assp
77
78==== Assq
79
80==== Assv
81
82==== At
83
84==== BigList?
85
86==== BigList->list
87
88==== Cons
89
90==== Cycle
91
92==== Cycle-times
93
94==== Drop
95
96==== Drop-while
97
98==== Drop-until
99
100==== Eager?
101
102==== Eq?
103
104==== Eqp?
105
106==== Equal?
107
108==== Eqv?
109
110==== Every?
111
112==== Filter
113
114==== Fold-left
115
116==== Fold-left0
117
118==== Fold-right
119
120==== Fold-right0
121
122==== For
123
124==== For-each
125
126==== First
127
128==== Index
129
130==== Iterate
131
132==== Iterate-times
133
134==== Iterate-until
135
136==== Iterate-while
137
138==== Lazy?
139
140==== Length
141
142==== List
143
144==== List?
145
146==== List-of?
147
148==== Map
149
150==== Member
151
152==== Memp
153
154==== Memq
155
156==== Memv
157
158==== Merge
159
160==== Null?
161
162==== Print
163
164==== Range
165
166==== Read-forever
167
168==== Remove
169
170==== Remp
171
172==== Remq
173
174==== Remv
175
176==== Repeat
177
178==== Repeat-times
179
180==== Rest
181
182==== Reverse
183
184==== Reverse*
185
186==== Scan-left
187
188==== Scan-right
189
190==== Some?
191
192==== Sort
193
194==== Sorted?
195
196==== Take
197
198==== Take-until
199
200==== Take-while
201
202==== Unzip
203
204==== Zip
205
206==== integers
207
208==== nil
209
210==== eos
211
212=== Dependencies
213
214bindings
215
216=== Examples
217
218<enscript highlight=scheme>
219
220(import biglists bindings)
221
222(First nil) ;-> eos
223
224(At 2 '(0 1 2 3 4)) ;-> 2
225
226(At 3 (List 0 1 2 3 4) ;-> 3
227
228(List? (List 0 1 2 3 4) ;-> #t
229
230(List? '(0 1 2 3 4)) ;-> #t
231
232(BigList->list (Take 4 integers)) ;-> '(0 1 2 3)
233
234(First (Drop 4 integers)) ;-> 4
235
236(BigList->list (Reverse (List 0 1 2 3))) ;-> '(3 2 1 0)
237
238(Fold-right + 0 (List 1 2 3)) ;-> 6
239
240(Fold-left + 0 '(1 2 3)) ;-> 6
241
242(Length  (Scan-right + 0 four four)) ;-> 4
243
244(BigList->list 12 (Zip (List 0 1 2 3) integers))
245  ;-> '(0 0 1 1 2 2 3 3 4 5 6 7)
246
247(BigList->list 10 (nth-value 0 (Unzip integers)))
248  ;-> '(0 2 4 6 8 10 12 14 16 18)
249
250(BigList->list 10 (nth-value 1 (Unzip integers)))
251  ;-> '(1 3 5 7 9 11 13 15 17 19)
252
253(Merge <= '(0 1 2 3 4) '(0 1 2 3 4))
254  ;-> '(0 0 1 1 2 2 3 3 4 4)
255
256(BigList->list (Sort <= (Append (List 0 1 2 3) (List 0 1 2 3))))
257  ;-> '(0 0 1 1 2 2 3 3)
258
259(BigList->list 10 (Memv 3 integers))
260  ;-> '(3 4 5 6 7 8 9 10 11 12)
261
262(BigList->list (Assp odd? (List (List 0 5) (List 1 6) (List 2 7))))
263  ;-> '(1 6)
264
265(BigList->list 5 (Range #f)) ;-> '(0 1 2 3 4)
266
267(BigList->list (Iterate-times add1 5 1))
268  ;-> '(1 2 3 4 5)
269
270(bind (x . xs) integers (list x (BigList->list 5 xs)))
271  ;-> '(0 (1 2 3 4 5))
272
273(bind (x (y . ys) z) (List 1 integers 3)
274  (list x y z (BigList->list 5 ys)))
275  ;-> '(1 0 3 (1 2 3 4 5))
276
277(BigList->list (For ((x (List 0 1 2 3)) (add1 x))) ;  map
278  ;-> '(1 2 3 4))
279
280(BigList->list (For ((x (List 0 1 2 3 4 5 6) (odd? x))) x)) ; filter
281  ;-> '(1 3 5))
282
283(BigList->list (For ((n (List 0 1 2 3 4 5 6) (positive? n) (even? n)))
284                 (* 10 n)))
285  ;-> '(20 40 60))
286
287(BigList->list (For ((c (List 'A 'B 'C)) ;lazy
288                     (k '(1 2 3 4))) ;eager
289                 (list c k)))
290  ;-> '((A 1) (A 2) (A 3) (A 4)
291  ;     (B 1) (B 2) (B 3) (B 4)
292  ;     (C 1) (C 2) (C 3) (C 4))
293
294(For ((c '(A B C)) ;eager
295      (k (List 1 2 3 4))) ;lazy
296  (list c k))
297  ;-> '((A 1) (A 2) (A 3) (A 4)
298  ;     (B 1) (B 2) (B 3) (B 4)
299  ;     (C 1) (C 2) (C 3) (C 4))
300
301</enscript>
302
303== Last update
304
305Mar 15, 2019
306
307== Author
308
309[[/users/juergen-lorenz|Juergen Lorenz]]
310
311== License
312
313 Copyright (c) 2014-2019, Juergen Lorenz
314 All rights reserved.
315
316 Redistribution and use in source and binary forms, with or without
317 modification, are permitted provided that the following conditions are
318 met:
319 
320 Redistributions of source code must retain the above copyright
321 notice, this list of conditions and the following disclaimer.
322 
323 Redistributions in binary form must reproduce the above copyright
324 notice, this list of conditions and the following disclaimer in the
325 documentation and/or other materials provided with the distribution.
326 Neither the name of the author nor the names of its contributors may be
327 used to endorse or promote products derived from this software without
328 specific prior written permission.
329   
330 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
331 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
332 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
333 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
334 HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
335 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
336 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
337 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
338 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
339 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
340 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
341
342== Version History
343
344; 0.1 : initial import
345
346
347
Note: See TracBrowser for help on using the repository browser.