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

Last change on this file since 37400 was 37400, checked in by juergen, 19 months ago

simple-loops 1.0

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