On Tue, 30 Nov 2004 14:58:13 -0800, Larry Wall <[EMAIL PROTECTED]> wrote: > But then it's not a general iterator iterator. Plus it has the Unicode > taint... > > Back to reality, another thought to weave in here is that something > like > > for $iterator.each -> $x {...} > > might specify that there may be ordering dependencies from loop > iteration to loop iteration, whereas (since junctions are inherently > unordered) saying: > > for $iterator.all -> $x {...} > > explicitly tells the system it can parallelize the loop without worrying > about interation between iterations.
I've been thinking about it, and this strikes me as really odd. Perl 5 is full of nice shortcuts. One of them is: for (@array) { which takes the place of for (my $i = 0; $i < @array; $i++) { which is what you'd have to do in a lot of other languages. What I mean is that Perl takes an array and makes an iterator out of it. Sure, you probably don't think about it like that, but the behavior is the same (who says arrays need to iterate starting at element zero?). Java just introduced something similar in 1.5. The odd thing is that here we are designing Perl 6, and we're trying to take an iterator and make it into an array so that we can turn it back into an iterator again. It seems like we should just use it as an iterator:: for $iterator -> $elem { ... } Your message leads me to believe that for all(1, 2, 3) -> $num { ... } is already a special case that will or can be recognized and optimized. If so, having special behavior for an iterator shouldn't be much more difficult (though I'm not sure of the correctness or full ramifications of this statement). That would have the added benefit of letting me write this: for open($filename) or die -> $line { ... } which I like. A method could be used for retrieving the next line/char/byte/whatever: my $fh = open $filename or die; my $line = $fh.next where C<.next> splits on the input record separator. C<.next_byte> and family could be implemented on top of that as well. The biggest problem I see (and I may just be blind) is that for $iterator -> $x { ... } is slightly ambiguous to the programmer, which makes me want angle brackets back. Other syntax could be used (though we seem to be drawing a blank there), but I don't like the idea of using a method (see Iterator->Array->Iterator above). I also like the idea of general iterators. Really like it. Perl 5 had it via C<tie>, but it wasn't so pretty. Supposing class Filehandle does Iterate; # Iterate or Iterator? we have an easy way to create new iterators. I'm not sure how useful they would be in Perl 6 (how do iterators compare to lazy lists?), but I can see if being useful. For instance, perhaps a more idiomatic DBI could be written like this: my $sth = $dbh.prepare('SELECT * FROM foo'); for $sth.execute.iter -> $results { ... } Which be even cuter like this (I think): for iter($sth.execute) -> $results { ... } where iter creates an Iterator object that just knows to call C<.next> on its argument. Anyway, take it for what its worth. I'm aware of how ridiculous many of the things we (that includes me) say are, but perhaps I've said something useful. Hoping I haven't removed all doubt of my foolishness, -- matt diephouse http://matt.diephouse.com