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

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

Thread Previous | Thread Next
From:
Matt Diephouse
Date:
December 4, 2004 08:15
Subject:
Re: iteration (was Re: Angle quotes and pointy brackets)
Message ID:
198c87380412040815704d1410@mail.gmail.com
On Sat, 04 Dec 2004 08:59:24 -0700, David Green <plato@edmc.net> wrote:
> In article <198c87380412032209261dcb17@mail.gmail.com>,
>  mddiep@gmail.com (Matt Diephouse) wrote:
> >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
> 
> Maybe the class doesn't do it, but one of its methods does?  Then you
> can call it whatever makes sense.

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.

> >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.
> 
> That still seems too cumbersome to me.  Isn't it "for" that knows to
> call .next (or .sequel, whatever)?  I'm thinking that that is the
> point of "for $foo", which should be approximately the same as "while
> $foo.next".  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.

> >Hoping I haven't removed all doubt of my foolishness,
> 
> I'm hoping this reply reassures you.

Thanks.

-- 
matt diephouse
http://matt.diephouse.com

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