Jonathan Scott Duff <[EMAIL PROTECTED]> writes:
> On Fri, Oct 26, 2001 at 01:13:42PM -0400, Aaron Sherman wrote:
>> It does make me think, though... Would it make sense to have an
>> accessor operator? For example, in Perl5 I would do this:
>>
>> sub foo {
>> my $self = shift;
>> my $old = $self->{foo};
>> # So $obj->foo(undef) will work
>> if (@_) {
>> $self->{foo} = shift @_;
>> }
>> return $old;
>> }
>>
>> In Perl6 with the unary ., that becomes:
>>
>> sub .foo (*@args) {
>> my $old = $.{foo};
>> # So $obj.foo(undef) will work
>> $.{foo} = shift @args if @args;
>> return $old;
>> }
>
> Actually, I think it becomes:
>
> sub foo is method {
> my $old = .foo;
> .foo = shift if @_;
> return $old;
> }
>
> But, I could be wrong. Any Damians care to enlighten? :-)
Perl 6 Perl 5
my $old = .foo my $old = $self->foo;
my $old = $.foo Um... ah... It's accessing an instance
variable. Which Perl 5 doesn't have.
well, you can mock it up with:
Note that this is a variable that is
inaccessible to anything but the object's
methods...
--
Piers
"It is a truth universally acknowledged that a language in
possession of a rich syntax must be in need of a rewrite."
-- Jane Austen?