develooper Front page | perl.perl6.language | Postings from December 2004

Re: iteration (was Re: Angle quotes and pointy brackets)

Thread Previous | Thread Next
From:
David Green
Date:
December 6, 2004 02:17
Subject:
Re: iteration (was Re: Angle quotes and pointy brackets)
Message ID:
plato-737217.03170606122004@x6.develooper.com
In article <198c87380412040815704d1410@mail.gmail.com>,
 mddiep@gmail.com (Matt Diephouse) wrote:
>On Sat, 04 Dec 2004 08:59:24 -0700, David Green <plato@edmc.net> wrote:

>C<does Iterate> signifies a role named "Iterate". Roles are sort of a
>mix of interfaces and mixins (as I understand it -- I'm still waiting
>for E12). So saying a class fulfills a role just means that it
>provides certain methods. In this case, I was saying class with the
>Iterate role would provide a C<.next> method.

I thought of that at first, but I don't want to have to call my 
iterating method "next" any more than I want to *have* to call my 
constructor "new".  But there is a difference in that "new" is called 
by some user who is supposed to have read the documentation, whereas 
"next" needs to get implicitly called by "for".  

So maybe it really should be a Role.  (One can always provide methods 
with better names that simply call the "real" .next, .prev, .final, 
etc. for increased user-friendliness.)

    &eof := &final;    # is that how to create an alias for a sub/method?

> >We've got "while" for looping, ".next" for iterating,
> > and "for" for doing both in one convenient little shortcut.
>
>But for needs to know if it has an iterator or a list. You don't want
>it iterating over things you didn't want it iterating. In this case, I
>was suggesting making an, though I suppose something like
>C<$sth.execute> could just return one.

Well, I was looking at lists as being kinds of iterators. If you want 
to "for" over an iterator without actually iterating it, I guess 
you'd have to make a reference to it or put it inside a list (so the 
list would be iterated instead).


          - David "iterate: to go around and around, like my head" Green

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About