Re: RFC 299 (v1) C<@STACK> - a modifyable C<caller()>

[email protected] (Buddha Buck) Mon, 25 Sep 2000 19:19:57 -0400
Newsgroups perl.perl6.language.subs
Message-ID <20000925231957.5DA7415713@zaphod>
> Instead of a whole new array, why not just add an additional variable to
> caller() that pops off that many stacks permanently?
> 
>    $pkg = caller(1);       # back one stack frame
>    $pkg = caller(1, 2);    # back one stack, "pop" off
>                            # two stack frames also
> 
> Or, add a new stack() function that returns an array of the frame(s)
> popped off:
> 
>    @frame = stack;         # pop off one frame
>    stack(2);               # pop off two frames
> 
> But making a special variable which can only be popped off and breaks
> the nice encapsulation of the caller() function? Bleech, honestly.

It would be interesting if we could have something like:

sub bar {
  $frame = caller();
  foo($frame);
  ...
}
sub foo {
   ...
   stack($_[0]);  # pop call stack until $_[0] == caller()
   return 0;      # return from bar
}

Then we'd have an interesting, restricted form of continuations to play 
with.

> 
> -Nate

-- 
     Buddha Buck                             [email protected]
"Just as the strength of the Internet is chaos, so the strength of our
liberty depends upon the chaos and cacophony of the unfettered speech
the First Amendment protects."  -- A.L.A. v. U.S. Dept. of Justice