> -----Original Message----- > From: Aaron Sherman [mailto:[EMAIL PROTECTED] > Sent: Friday, 23 April, 2004 03:12 PM > To: John Siracusa > Cc: Perl 6 Language > Subject: Re: A12: default accessors and encapsulation > > > On Tue, 2004-04-20 at 10:13, John Siracusa wrote: > > On 4/19/04 7:20 PM, Larry Wall wrote: > > > On Mon, Apr 19, 2004 at 06:53:29PM -0400, John Siracusa wrote: > > > : Yeah, that's exactly what I don't want to type over and over :) > > > > > > I really don't understand what you're getting at here. First you > > > complain that you'd rather write an ordinary method, and then you > > > complain that you have to. Have I met someone lazier than me? :-) > > > > Possibly :) Here's what I'm saying. In the first version of a > class, there > > will probably be a lot of simple get/set attributes. It's > convenient not to > > have to write any explicit methods for those. > > > > If I accept the default accessors that you get "for free" when > a class "has > > $.foo is rw", then that means the users of my class can do $obj.foo = > > whatever in order to set the foo attribute. > > And if you override the accessor, you can: > > multi method foo(Str $blah = undef) is rw($new) { > (my($old),$.foo)=($.foo,$blah//$new); > .update_the_world_in_some_cool_way(); > return $old > }
I don't understand this. What's the $new doing? And if you've only got one of them, do you need multi, or just an optional argument? method foo(Str ?$new) is rw { my $old = $.foo; if (defined($new)) { $.foo = $new; .update_the_world(); } return $old; }