The collectors Module¶
- collecting Statement Macro¶
Collect values into a named or unnamed collector. A collector may be, for example, a
<collection>, a number into which values are accumulated, etc.- Macro Call:
collecting ([name] [as type]) [ body ] end [ collecting ]
- Parameters:
name – A Dylan variable-name BNF. If omitted, the collection is returned from the
collectingmacro call. If supplied, the caller is responsible for callingcollected(name)to retrieve the collection before the call to collecting terminates.type – A Dylan type. The default value is
<list>.body – A Dylan body BNF.
- Discussion:
Binds name (or a default variable name if name is not supplied) to a collector that can efficiently collect new values into the collection when
collector the relatedcollect-*macros are called.- Example:
collecting () collect(1); collect(2) end; // => #(1, 2) collecting () collect(1); collect-first(2) end; // => #(2, 1) collecting (as <integer>) collect(1); collect(2) end; // => 3 collecting (a, b, c) collect-into(a, 1); collect-into(b, 2); collect-into(c, 3); values(collected(a), collected(b), collected(c)) end; // => #(1), #(2), #(3)
- collect Macro¶
- Discussion:
Collect a value at the end of the unnamed collector:
collect(100)May only be used whencollecting () ... endwas called with no arguments.- See also:
- collect-first Macro¶
- Discussion:
Collect a value at the beginning of the unnamed collector:
collect-first(100)May only be used whencollecting () ... endwas called with no arguments.- See also:
- collect-last Macro¶
- Discussion:
Collect a value at the end of the unnamed collector:
collect-last(100)May only be used whencollecting () ... endwas called with no arguments.- See also:
- collect-into Macro¶
- Discussion:
Collect a value at the end of a named collector:
collect-into(c, 100)May only be used whencollecting (c) ... endwas called with arguments.- See also:
- collect-first-into Macro¶
- Discussion:
Collect a value at the beginning of a named collector:
collect-first-into(c, 100)May only be used whencollecting (c) ... endwas called with arguments.- See also:
- collect-last-into Macro¶
- Discussion:
Collect a value at the end of a named collector:
collect-last-into(c, 100)May only be used whencollecting (c) ... endwas called with arguments.- See also:
- collected Macro¶
- Discussion:
Retrieve the value of the collection associated with a collector.
- Example:
collecting () ...; do(f, collected()); ... end collecting (a, b) ...; do(f1, collected(a)); do(f2, collected(b)); ... end
- See also:
- collector-protocol Open Generic function¶
- Signature:
collector-protocol class => new-collector add-first add-last add-sequence-first add-sequence-last collection
- Parameters:
class – An instance of
<object>.
- Values:
new-collector – An instance of
<object>.add-first – A
<function>that accepts the collection and a value and adds the value to the beginning of the collection.add-last – A
<function>that accepts the collection and a value and adds the value to the end of the collection.add-sequence-first – An instance of
<function>. Not yet implemented.add-sequence-last – An instance of
<function>. Not yet implemented.collection – A
<function>that receives the collector and returns the collection.
- See also: