Re: RFC 299 (v1) C<@STACK> - a modifyable C<caller()>
[email protected] (Nathan Wiger) Mon, 25 Sep 2000 13:51:49 -0700
| Newsgroups | perl.perl6.language.subs |
|---|---|
| Message-ID | <[email protected]> |
> Add a new special variable, C<@STACK> to replace the C<caller()>
> function. Allow people to modify the call stack in certain, very
> restricted ways.
> Perl 6 => Perl 5
> $STACK[-1] = [caller(0)];
> $STACK[-2] = [caller(1)];
I strongly agree with the opinion that we should try and get away from
special variables and switches in favor of functions and pragmas.
Witness 'use base' instead of '@ISA', 'use warnings', and so on.
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.
-Nate