Debian Codegraph @

doc/collecting.html

raw
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <HTML>
3 <HEAD>
4 <TITLE>Macro COLLECTING, WITH-COLLECTORS</TITLE>
5 <LINK REL="stylesheet" HREF="style.css" type="text/css">
6 </HEAD>
7 <BODY>
8
9 <p><p><i>Macro</i> <b>COLLECTING</b></a></a> <p>
10 <p><b>Syntax:</b><p>
11
12 <p>
13
14 <p><b>collecting</b> <i>form*</i> => <i>result</i><p>
15
16 <p><b>with-collectors</b> <i>(collector*) form*</i> => <i>result</i>*<p>
17 <p>
18 <p><b>Arguments and Values:</b><p>
19 <p>
20 <i>forms</i>---an <a
21 href="http://www.lispworks.com/documentation/HyperSpec/Body/glo_i.html#implicit_progn">implicit
22 progn</a>.
23
24 <p><i>collector</i>---a symbol which will have a collection function bound to it.
25
26 <p><i>result</i>---a collected list.
27
28 <p>
29 <p><b>Description:</b><p>
30 <p>
31 <b>collecting</b> collects things into a list. Within the
32 body of this macro, the <b>collect</b> function will collect its
33 argument into <i>result</i>.
34
35 <p><b>with-collectors</b> collects some things into lists. The
36 <i>collector</i> names are defined as local functions which each
37 collect into a separate list. Returns as many values as there are
38 collectors, in the order they were given.
39
40 <p><b>Exceptional situations:</b><p>
41 <p>
42
43 <p>If the <i>collector</i> names are not all symbols, a
44 <b>type-error</b> will be signalled.
45
46 <p><b>Examples:</b>
47
48 <pre>
49 (collecting (dotimes (x 10) (collect x))) => (0 1 2 3 4 5 6 7 8 9)
50
51 (multiple-value-bind (a b)
52 (with-collectors (x y)
53 (x 1)
54 (y 2)
55 (x 3))
56 (append a b)) => (1 2 3)
57 </pre>
58
59 <p><p><b>Implementation notes:</b></p>
60
61 <p>Opinions differ on how a collection macro should work. There are
62 two major points for discussion: multiple collection variables and
63 implementation method.</b>
64
65 <p>There are two main ways of implementing collection: sticking
66 successive elements onto the end of the list with tail-collection, or
67 using the PUSH/NREVERSE idiom. Tail-collection is usually faster,
68 except on CLISP, where PUSH/NREVERSE is a little faster because it's
69 implemented in C which is always faster than Lisp bytecode.</p>
70
71 <p>The <b>collecting</b> macro only allows collection into one list,
72 and you can't nest them to get the same effect as multiple collection
73 since it always uses the <b>collect</b> function. If you want to
74 collect into multiple lists, use the <b>with-collect</b> macro.</p>
75
76 <p class="footer"><hr><a href="index.html">Manual Index</a></p>
77
78 </body></html>