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? :-) > So, since this is likely to be fairly common, could we perhaps have > a shortcut? I'm not so sure that a) we need short-cut and b) that one doesn't already fall out of existing er, proposed language features. -Scott -- Jonathan Scott Duff [EMAIL PROTECTED]