I understand your example. In fact, it further clarifies your earlier note.
But that's not what I meant. I was thinking that access was through a
variable, not understanding the real point of the syntax.
Audrey Tang audreyt-at-audreyt.org |Perl 6| wrote:
John M. Dlugosz wrote:
That seems to be saying that using the method-call form is preferred, as
it abstracts whether it is a real hard attribute or not.
Er, it is not so.
The $.foo notation is good not only for calling accessors, but also as
a way to specify context when calling oneself's methods. Consider:
class Foo {
method bar ($x, $y) { ... }
method baz (
$.bar: 1, 2;
@.bar: 3, 4;
}
}
Here we are simply typing $.bar as a shorthand of $(self.bar), and
@.bar as @(self.bar), as well as supplying them with arguments; they
do not mandate that there exists a "bar" attribute for our class.
In other words, there needs to be no real hard attribute "bar", no
matter if you call the "bar" method as self.bar(), $.bar(), or simply
$.bar.
Cheers,
Audrey