Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #5807 > unrolled thread
| Started by | Victor Porton <porton@narod.ru> |
|---|---|
| First post | 2015-09-04 21:48 +0300 |
| Last post | 2015-09-04 20:07 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.programming
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
| From | Victor Porton <porton@narod.ru> |
|---|---|
| Date | 2015-09-04 21:48 +0300 |
| Subject | A class being BOTH a factory of iterators and an iterator |
| Message-ID | <mscp1o$4ip$1@speranza.aioe.org> |
Is it sane that a class which is a factory for iterators, itself to be an iterator (a default iterator so to say)? It may be convenient especially for Web masters which don't know what iterator is. Your opinion? -- Victor Porton - http://portonvictor.org
[toc] | [next] | [standalone]
| From | Kaz Kylheku <kaz@kylheku.com> |
|---|---|
| Date | 2015-09-04 20:07 +0000 |
| Message-ID | <20150904125307.138@kylheku.com> |
| In reply to | #5807 |
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 }
}
[toc] | [prev] | [standalone]
Back to top | Article view | comp.programming
csiph-web