Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #5809
| From | Kaz Kylheku <kaz@kylheku.com> |
|---|---|
| Newsgroups | comp.programming |
| Subject | Re: A class being BOTH a factory of iterators and an iterator |
| Date | 2015-09-04 20:07 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <20150904125307.138@kylheku.com> (permalink) |
| References | <mscp1o$4ip$1@speranza.aioe.org> |
On 2015-09-04, Victor Porton <porton@narod.ru> wrote:
> Is it sane that a class which is a factory for iterators, itself to be an
> iterator (a default iterator so to say)?
Not any more than for a complex_number class to also be a network_stream,
with a disconnect method. :)
> It may be convenient especially for Web masters which don't know what
> iterator is.
Programmers can be insulated from explicit use of iterator objects with
syntactic sugar. That is to say, some "for each var in obj" type construct can
compile to code which instantiats an appropriate iterator (which goes with the
type of obj). This iterator is stored in an anonymized, programmer-invisible
local variable and used implicitly by the syntax to step var through the
elements of obj.
An iterator factory can be invoved if the iterator type can't be statically
determined.
for item in obj { block }
-- translate -->
var __iter_0025 = iter_factory(typeof(obj)).instantiate(obj);
while (__iter_0025.has_more()) {
var item = __iter_0025.get_another();
{ block }
}
Back to comp.programming | Previous | Next — Previous in thread | Find similar | Unroll thread
A class being BOTH a factory of iterators and an iterator Victor Porton <porton@narod.ru> - 2015-09-04 21:48 +0300 Re: A class being BOTH a factory of iterators and an iterator Kaz Kylheku <kaz@kylheku.com> - 2015-09-04 20:07 +0000
csiph-web