@@ -5,21 +5,111 @@ The collectors Module
5
5
.. current-library :: collections
6
6
.. current-module :: collectors
7
7
8
+ .. macro :: collecting
9
+ :statement:
10
+
11
+ Collect values into a named or unnamed collector. A collector may be, for example, a
12
+ :drm: `<collection> `, a number into which values are accumulated, etc.
13
+
14
+ :macrocall:
15
+ .. parsed-literal ::
16
+
17
+ collecting ([`name `] [as `type `])
18
+ [ `body ` ]
19
+ end [ collecting ]
20
+
21
+ :parameter name: A Dylan variable-name *BNF *. If omitted, the collection is returned
22
+ from the :macro: `collecting ` macro call. If supplied, the caller is responsible for
23
+ calling ``collected(name) `` to retrieve the collection before the call to
24
+ `collecting ` terminates.
25
+ :parameter type: A Dylan type. The default value is :drm: `<list> `.
26
+ :parameter body: A Dylan body *BNF *.
27
+
28
+ :description:
29
+
30
+ Binds *name * (or a default variable name if *name * is not supplied) to a collector
31
+ that can efficiently collect new values into the collection when :macro: `collect `
32
+ or the related ``collect-* `` macros are called.
33
+
34
+ :example:
35
+
36
+ .. code-block :: dylan
37
+
38
+ collecting () collect(1); collect(2) end;
39
+ // => #(1, 2)
40
+
41
+ collecting () collect(1); collect-first(2) end;
42
+ // => #(2, 1)
43
+
44
+ collecting (as <integer>) collect(1); collect(2) end;
45
+ // => 3
46
+
47
+ collecting (a, b, c)
48
+ collect-into(a, 1);
49
+ collect-into(b, 2);
50
+ collect-into(c, 3);
51
+ values(collected(a), collected(b), collected(c)
52
+ end;
53
+ // => #(1), #(2), #(3)
54
+
8
55
.. macro :: collect
9
56
57
+ :description: Collect a value at the end of the unnamed collector: ``collect(100) ``
58
+ May only be used when ``collecting () ... end `` was called with no arguments.
59
+
60
+ :seealso: :macro: `collecting `
61
+
10
62
.. macro :: collect-first
11
63
12
- .. macro :: collect-first-into
64
+ :description: Collect a value at the beginning of the unnamed collector:
65
+ ``collect-first(100) `` May only be used when ``collecting () ... end `` was called
66
+ with no arguments.
13
67
14
- .. macro :: collect-into
68
+ :seealso: :macro: ` collecting `
15
69
16
70
.. macro :: collect-last
17
71
72
+ :description: Collect a value at the end of the unnamed collector:
73
+ ``collect-last(100) `` May only be used when ``collecting () ... end `` was called
74
+ with no arguments.
75
+
76
+ :seealso: :macro: `collecting `
77
+
78
+ .. macro :: collect-into
79
+
80
+ :description: Collect a value at the end of a named collector: ``collect-into(c,
81
+ 100) `` May only be used when ``collecting (c) ... end `` was called with arguments.
82
+
83
+ :seealso: :macro: `collecting `
84
+
85
+ .. macro :: collect-first-into
86
+
87
+ :description: Collect a value at the beginning of a named collector:
88
+ ``collect-first-into(c, 100) `` May only be used when ``collecting (c) ... end `` was
89
+ called with arguments.
90
+
91
+ :seealso: :macro: `collecting `
92
+
18
93
.. macro :: collect-last-into
19
94
95
+ :description: Collect a value at the end of a named collector: ``collect-last-into(c,
96
+ 100) `` May only be used when ``collecting (c) ... end `` was called with arguments.
97
+
98
+ :seealso: :macro: `collecting `
99
+
20
100
.. macro :: collected
21
101
22
- .. macro :: collecting
102
+ :description: Retrieve the value of the collection associated with a collector.
103
+
104
+ :example:
105
+
106
+ .. code-block :: dylan
107
+
108
+ collecting () ... map(f, collected()) ... end
109
+
110
+ collecting (a, b) ... map(f1, collected(a)); map(f2, collected(b)); ... end
111
+
112
+ :seealso: :macro: `collecting `
23
113
24
114
.. generic-function :: collector-protocol
25
115
:open:
@@ -28,9 +118,13 @@ The collectors Module
28
118
29
119
:parameter class: An instance of :drm: `<object> `.
30
120
:value new-collector: An instance of :drm: `<object> `.
31
- :value add-first: An instance of :drm: `<function> `.
32
- :value add-last: An instance of :drm: `<function> `.
33
- :value add-sequence-first: An instance of :drm: `<function> `.
34
- :value add-sequence-last: An instance of :drm: `<function> `.
35
- :value collection: An instance of :drm: `<function> `.
121
+ :value add-first: A :drm: `<function> ` that accepts the collection and a value and adds
122
+ the value to the beginning of the collection.
123
+ :value add-last: A :drm: `<function> ` that accepts the collection and a value and adds
124
+ the value to the end of the collection.
125
+ :value add-sequence-first: An instance of :drm: `<function> `. **Not yet implemented. **
126
+ :value add-sequence-last: An instance of :drm: `<function> `. **Not yet implemented. **
127
+ :value collection: A :drm: `<function> ` that receives the collector and returns the
128
+ collection.
36
129
130
+ :seealso: :macro: `collecting `
0 commit comments