On 4/19/04 4:47 PM, [EMAIL PROTECTED] wrote: >> On 4/19/04 3:58 PM, Austin Hastings wrote: >> One work-around might be an alternate kind of default accessor that doesn't >> allow assignment: >> >> $dog.name # get >> $dog.name('foo') # set >> $dog.name = 'foo' # compile-time error > > I think we already have this. Just define a non-rw attribute and then > add your own writer as a multi-method. > > has Str $.name; > multi method name(Str $n) {$.name = $n;}
Yeah, that's exactly what I don't want to type over and over :) It's not much better than the old Perl 5 standby: sub name { @_ > 1 ? $_[0]->{'name'} = $_[1] : $_[0]->{'name'} } since once I have to write something, the time and effort savings is pretty much cancelled out. -John