in reply to Re: Iterating & Playing with Caller's Pads
in thread Iterating & Playing with Caller's Pads

I'd just like to be able to write operators that act like any other builtins. The limitation isn't stopping me from doing anything I need to do. It just irks me that you can't do it. It just seems to me that I should be able to say somthing like
while( my @els = elements @array,3){ .. do something } # instead of my $iter = make_iter(@array); while (my @els = @{ $iter->() } ){ .. do something }
I would also think that it might solve part of the problem of implementing coroutines and continuations.

Excuse my ignorance, what do you mean by "point release", do you mean newer versions of perl? I would think that behavior wouldn't change that much but I honestly have no idea.

-Lee

"To be civilized is to deny one's nature."

Replies are listed 'Best First'.
Re: Re: Re: Iterating & Playing with Caller's Pads
by broquaint (Abbot) on Sep 27, 2002 at 13:20 UTC
    It just irks me that you can't do it. It just seems to me that I should be able to say somthing like ...
    ... this?
    { my $pos = 0; sub elements(\@$) { my($ar, $n) = @_; my $range = $pos + $n < @$ar ? $pos + ($n - 1) : $#{$ar}; my @ret = @$ar[ $pos .. $range ]; $pos += $n; return @ret ? @ret : (); } } my @ar = qw( foo bar baz one two three ichi ni san xxx ); while(my(@chunk) = elements(@ar, 3)) { print "got: @chunk\n"; } __output__ got: foo bar baz got: one two three got: ichi ni san got: xxx yy
    Or am I missing the point?
    HTH

    _________
    broquaint

      My intended one. I gave a very bad example. I'm talking lazy iterators here. The example should have stated "non-destructively" grab elements. I see a lot of uses for this type of scoping, but iterators would be the biggest. I'm talking lazy iterators here.

      -Lee

      "To be civilized is to deny one's nature."