Paul Seamons skribis 2005-04-25 9:52 (-0600):
> a way back
What is this "way back" you repeatedly mention?
If it is having a name for the invocant, then there has always been one:
method foo ($self:) {
for (1..10) {
$self.method(.sqrt)
}
}
Or, well, two:
method foo {
my $self := $_;
...
}
Three, even:
method foo {
my $self = \$_;
for (1..10) {
$$self.method(.sqrt)
}
}
And probably even more. TAMT0WTDI! :)
> Now if we can introduce another way back so that we can always get to the
> invocant if we want to, then I'd say lets leave .meth always working on $_ .
> It does have beauty and simplicity.
Agreed!
> $^.meth; # is the invocant
> $^1.meth; # is the first invocant
> $^2.meth; # is the second invocant
I don't understand the concept of multiple invocants. How does that
work?
$^ as an alias for the invocant works for me, because "" sorts before
anything else, and the invocant's just the 0th argument.
> The rules then are simple. .meth always operates on $_. $_ is always the
> current topic. $_ defaults to the invocant of the method.
Yes! The problem isn't that this hasn't already been thought of -- it is
the current spec even.
However, the discussion is about changing these simple, clear, and
useful rules to a more complex situation of choosing a default based on
what the default will be used for, making the default for methods the
invocant rather than $_. I hate those plans and would love to see the
current spec, that is as you decribe above, implemented in the "final"
version.
(Or well, I believed this was the spec until I tried finding it. I can
find the stuff about .method defaulting to $_ in S12, but $_ being an
alias for the invocant is harder to find.)
Juerd
--
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html
http://convolution.nl/gajigu_juerd_n.html