On Mon, Sep 20, 2004 at 07:25:14AM -0600, Luke Palmer wrote:
: Perl 6 is making it easier to define custom block constructs like this
: one. I worry about:
:
: method foo () {
: preserve {
: .bar;
: }
: }
:
: This one's a tad more subtle. Normally preserve's block would be 0-ary.
: But in this case it's unary, since it implicitly references $_.
:
: Is there a way to declare preserve so that its block will always be
: parsed 0-ary? "if" is certainly able to do this (consider the above
: example with s/preserve/if $baz/).
Such a block is parsed as 1-ary, but with an implicit argument that
defaults to the caller's $_, something like:
preserve sub ($_ = $CALLER::_) {
.bar;
}
Then it effectively becomes a run-time decision by "preserve" whether
to treat it as 0-ary or 1-ary.
Larry