in reply to Iterating & Playing with Caller's Pads

Cute.

But massive overkill, I'd think.

Why not just get the user to pass you a reference to a lexical you can use to store your magic? Or even use as your key...

The iterator syntax is cute, but is it worth that much effort? It would likely break at every point release, and I don't think you'd get much buyin from p5p for adding tests to make sure this kind of stuff keeps working from release to release...
--
Mike

  • Comment on Re: Iterating & Playing with Caller's Pads

Replies are listed 'Best First'.
Re: Re: Iterating & Playing with Caller's Pads
by shotgunefx (Parson) on Sep 27, 2002 at 12:25 UTC
    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."
      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."