In article <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] (Brent 'Dax' Royal-Gordon) wrote:
>I'm going to pull a Larry and think out
>loud for a minute here. Note that I speak authoritatively here,
Noted. Or not. =)
>Treating it like an array is wrong.
>On the other hand, what if a filehandle *is* an array? What if you
>can access it randomly and non-destructively?
I like this line of thought -- sure, arrays and iterators are
different, but they're also similar, so they ought to look similar in
at least some ways. We already think of files in a somewhat-array-
like manner ("Gimme line 42 of this file") rather than mere iterators
("Get the first 41 lines of this file, throw them away, and then gimme
the next one"), so why shouldn't Perl reflect that? Keeping the easy
things trivial and all...
An iterator can also be quite unlike an array (for instance a pipe,
where you can't jump back to the beginning, even inefficiently), but
I think those differences apply at a slightly higher level,
conceptually. (Or they would if we weren't forced by the language to
think of them differently at the lower level.) After all, if you
know you're dealing with a pipe, it would probably never even occur
to you to try accessing it randomly; on the other hand, if you don't
know whether your object is an array or a file or a pipe to begin
with, you're already in trouble.
>But .shift looks a bit awkward. I suggest a name change for .shift
>and .unshift, so that we have:
>
> push, pop
> pull, put
Hm, I like that, the parallelisms with the number of letters, and the
way they all begin with P. Plus the meanings make sense (you pull
something towards you -- that's the front end -- but when something
pops off, it goes flying away from you -- that's the back).
>So now we have:
> my $fh=open "foo.txt";
> say $fh.pull;
> for $fh.pullall {
I'm not crazy about "pullall". If the idea is we want to slurp up
the file right now, can't we use our flattening splatter? (for
[EMAIL PROTECTED] ...)
>And what about iterators in general? Well, if we can do it to
>filehandles, why not all iterators? An iterator is simply a lazy
>array copy that isn't accessed randomly;
Or maybe a lazy array is just an iterator (with some extra abilities
added on). But I'm all for taking advantage of the commonalities.
-David "which is related to another kind of laziness" Green