On Thu, 19 Sep 2002, Brent Dax wrote:
: Aaron Sherman:
: # topicalize: To default to C<$_> in a prototype (thus
: # acquiring the caller's current topic).
:
: Well, to topicalize a region of code is actually to specify a different
: topic, that is, a different value for $_. For example:
:
: $foo = new X;
: $bar = new Y;
:
: given $foo {
: print $_.type, "\n"; #prints "X"
:
: given $bar {
: #XXX we're using 'given' for this too, right?
: print $_.type, "\n"; #prints "Y"
: }
: }
Yes.
: (An aside: it strikes me that you could use C<given> as a scoped lexical
: alias, i.e.
:
: my $foo="foo";
: my $bar="bar";
:
: print $foo;
:
: given $bar -> $foo {
: print $foo;
: }
:
: print $foo;
:
: #prints "foobarfoo"
:
: Hmm...)
Sure, though it also aliases to $_.
: # signatureless sub: A sub that does not specify a prototype,
: # and thus has a default prototype of:
: #
: # sub($_//=$_){};
: #
: # ne?
:
: More like:
:
: a sub that was created with the arrow (->) or a bare block and
: does not specify a prototype, and thus has a default prototype
: of:
:
: -> ($_ //= $OUTER::_) { };
OUTER only works for lexical scopes. What you want is out-of-band access
to the $_ in the surrounding dynamic context
: Or some such. (Maybe C<$_ //= $_> will work, but I have reservations
: about that--especially about the possibility of that picking up $_
: dynamically instead of lexically. In some cases you want $_
: dynamically, in others lexically. Perhaps C<$_ is topic('lexical')> and
: C<$_ is topic('dynamic')>?)
The current thinking as of Zurich is that the "given" passes in
separate from the ordinary parameters:
sub ($a,$b,$c) is given($x) {...}
That binds the dynamically surrounding $_ to $x as an out-of-band
parameter. Can also bind to $_ to make it the current topic.
Not sure of the syntax for pointy subs yet. Maybe
-> ($a,$b,$c) is given($x) {...}
Larry