sub preserve(&) {...}
sub foo {
preserve {
$_[0]->bar;
}
}
That didn't call "bar" on the invocant of "foo", but rather on "undef",
because preserve's block was a hiding sub.
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/).
Luke
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