Perl6 RFC Librarian <[EMAIL PROTECTED]> writes:
[...]
> This RFC proposes that the right operand of a C<..> operator
> may be omitted in a list context, producing a lazily evaluated
> semi-finite list. It is further proposed that operations on
> such lists also be carried out lazily.
This would be nice, but I think should be folded into something more
general, like tieable first-class iterators. I'm still trying to pull
my thoughts together on this one, but lazy lists could be a special
case of iterators.
An `iterator' should have properties somewhat like these; the idea is
to allow the implementation of `map', `grep', `zip', `reduce', `for',
and maybe others. Also, as a first-class type, users should be able
to use all iterator facilities.
* clone underlying sequence (e.g. for creating return values of `map'
and `grep'). This (probably) returns a new iterator.
* advance one location. This might be permitted to be lazy, by
performing some special action (see below).
* read current element
* write current element
* test for end (I prefer this to the C++ method of explicitly
specifying an end, but I'm willing to listen to reason).
Iterators must be first-class. This means that they are a new
language type. They should *not* be objects, since we don't want to
force objects where they don't belong. However, they *should* be
another tieable type.
A semi-infinite iterator just never flags an end. It also needs to be
lazy, but perhaps this can fit in the above framework: "just" make
`map', `grep' and friends be driven by the return-value iterator. If
it's lazy, the input iterator is accessed as needed; if it's greedy,
the input iterator is slurped in in one go. As you can see, this is
the least thought-out bit of my proposal.
Another example of a "virtually" semi-infinite iterator is any file
handle. "perl -p" is just "print map { ... } <>", if "<>" is an input
iterator on lines of input.
Laziness really needs to be sorted out first, though.
[...]
--
Ariel Scolnicov |"GCAAGAATTGAACTGTAG" | [EMAIL PROTECTED]
Compugen Ltd. |Tel: +972-2-6795059 (Jerusalem) \ We recycle all our Hz
72 Pinhas Rosen St. |Tel: +972-3-7658514 (Main office)`---------------------
Tel-Aviv 69512, ISRAEL |Fax: +972-3-7658555 http://3w.compugen.co.il/~ariels