Damian Conway writes:
 > David Wheeler asked:
 > 
 > > How will while behave?
 > 
 > C<while> evaluates its first argument in scalar context, so:
 > 
 > 
 > >     while <$fh> {...}    # Iterate until $fh.readline returns EOF?
 > 
 > More or less. Technically: call <$fh.next> and execute the loop
 > body if that method returns true. Whether it still has the
 > automatic binding to $_ and the implicit definedness check is yet
 > to be decided.
 > 
 > 
 > >     while <$iter> {...}  # Iterate until $iter.each returns false?
 > 
 > Yes.
 > 

you mean "Iterate until $iter.next returns false?" 


what is the difference between the Iterator  and lazy array ?

am I right that it is just "interface" : lazy array is an iterator
object "inside" Array interface : ????

Larry Wall wrote:
> Then there's this approach to auto-iteration:
> 
>     my @dance := Iterator.new(@squares);
>     for @dance {

but then each is very simple method : 

class Iterator {
        method each( $self:) {
                my @a := $self ;
                return @a ; 
        }
}

but then probably we dont need two methods -- next and each . 
just like in perl5 each can determine the calling context 

class Iterator {
        method each( $self:) {
                when want Scalar {
                ...
                }
                when want Array {
                        my @a := $self ;
                        return @a ; 
                }
        }
}

and then <...> could be *really* the sugar for .each ( or .next if it
will be called so ) . in these examples 


> In a scalar context:
> 
>       <$fh>           # Calls $fh.readline (or maybe that's $fh.next???>
>       <$iter>         # Calls $iter.next
>       fibs()          # Returns iterator object
>       <fibs()>        # Returns iterator object and calls that
>                       #    object's C<next> method (see note below)
>       
> 
> In a list context:
> 
>       <$fh>           # Calls $fh.each
>       <$iter>         # Calls $iter.each
>       fibs()          # Returns iterator object
>       <fibs()>        # Returns iterator object and calls object's C<each>
> 

<...> *always* force call to .each ( which is context aware ) . 

but again all that is based on the assumtion that lazy array is just
Iterator object in the "cloth" of array ( variable container ) . so
this is a question . 

arcadi 




Reply via email to