Re: A12: default accessors and encapsulation

2004-04-23 Thread Larry Wall
On Fri, Apr 23, 2004 at 03:23:09PM -0400, Austin Hastings wrote: : > 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(); : > r

RE: A12: default accessors and encapsulation

2004-04-23 Thread Austin Hastings
> -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 wr

Re: A12: default accessors and encapsulation

2004-04-23 Thread Aaron Sherman
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 y

Re: A12: default accessors and encapsulation

2004-04-20 Thread Jonathan Scott Duff
On Tue, Apr 20, 2004 at 10:25:04PM +0200, Juerd wrote: > Brent 'Dax' Royal-Gordon skribis 2004-04-20 12:58 (-0700): > > method buffersize() > > will store { > > my $sqrt=$^v.sqrt; > > die "$^v is not a power of two" unless int($sqrt) == $sqrt; > > $.b

Re: A12: default accessors and encapsulation

2004-04-20 Thread John Williams
On Tue, 20 Apr 2004, Juerd wrote: > Brent 'Dax' Royal-Gordon skribis 2004-04-20 12:58 (-0700): > > method buffersize() > > will store { > > my $sqrt=$^v.sqrt; > > die "$^v is not a power of two" unless int($sqrt) == $sqrt; > > $.buffer = "\x[0]" x $^

Re: A12: default accessors and encapsulation

2004-04-20 Thread Juerd
Brent 'Dax' Royal-Gordon skribis 2004-04-20 12:58 (-0700): > method buffersize() > will store { > my $sqrt=$^v.sqrt; > die "$^v is not a power of two" unless int($sqrt) == $sqrt; > $.buffer = "\x[0]" x $^v; > } > { +$.buffer.bytes } Could

Re: A12: default accessors and encapsulation

2004-04-20 Thread John Siracusa
On 4/20/04 4:08 PM, Aaron Sherman wrote: > On Tue, 2004-04-20 at 15:40, John Siracusa wrote: >> On 4/20/04 2:37 PM, Larry Wall wrote: >>> It's wrong to introduce a fundamental asymmetry that breaks the contract >>> that an accessor can be used as a variable. >> >> Er, I think we have different def

Re: A12: default accessors and encapsulation

2004-04-20 Thread Brent 'Dax' Royal-Gordon
John Williams wrote: class Dog { has $.foo will FETCH { ... } will STORE { ... } ; } I'm not saying there is anything wrong with that, but John Siracusa is asking for something different, I think. A simple accessor which looks like a method without h

Re: A12: default accessors and encapsulation

2004-04-20 Thread Aaron Sherman
On Tue, 2004-04-20 at 15:40, John Siracusa wrote: > On 4/20/04 2:37 PM, Larry Wall wrote: > > It's wrong to introduce a fundamental asymmetry that breaks the contract that > > an accessor can be used as a variable. > > Er, I think we have different definitions of "accessor." I'm perfectly > happy

Re: A12: default accessors and encapsulation

2004-04-20 Thread Mark J. Reed
On 2004-04-20 at 11:37:18, Larry Wall wrote: > So do whatever you like to the declarations, but make sure you preserve > the symmetry and extensibility of > > $obj.foo([EMAIL PROTECTED], *%NONSENSE) # get value of $.foo > $obj.foo([EMAIL PROTECTED], *%NONSENSE) = 5 # set $

Re: A12: default accessors and encapsulation

2004-04-20 Thread John Siracusa
On 4/20/04 2:37 PM, Larry Wall wrote: > On Tue, Apr 20, 2004 at 01:15:24PM -0400, John Siracusa wrote: > : With that "has" line alone, you auto-magically get an accessor that works > : like this: > : > : $obj.foo# get value of $.foo > : $obj.foo(5) # set $.foo = 5 > > I don't care wha

Re: A12: default accessors and encapsulation

2004-04-20 Thread Larry Wall
On Tue, Apr 20, 2004 at 01:15:24PM -0400, John Siracusa wrote: : With that "has" line alone, you auto-magically get an accessor that works : like this: : : $obj.foo# get value of $.foo : $obj.foo(5) # set $.foo = 5 I don't care what syntactic sugar you put underneath, but if you expos

Re: A12: default accessors and encapsulation

2004-04-20 Thread John Williams
On Tue, 20 Apr 2004, Luke Palmer wrote: > John Williams writes: > > On Tue, 20 Apr 2004, Luke Palmer wrote: > > > There. Now here's the important part: in order to *use* all this, you > > > import whatever module defines it, and then say: > > > > > > class Dog { > > > method foo (?$ar

Re: A12: default accessors and encapsulation

2004-04-20 Thread John Siracusa
On 4/20/04 12:14 PM, Luke Palmer wrote: > Okay, well, I thought that my example did that, but apparently using > C and C is a little too complex... (my sentiments > are beginning to follow Larry's, in that I'm not sure you know what you > want -- perhaps you could give a hypotheical syntax?) There

Re: A12: default accessors and encapsulation

2004-04-20 Thread Mark J. Reed
On 2004-04-20 at 10:51:47, Luke Palmer wrote: > I guess I bogged down that message with the implementation, so the > result may have been easy to miss. That is what happened in my case. Apologies; it looks like your original solution would do the job nicely. As long as the requisite module come

Re: A12: default accessors and encapsulation

2004-04-20 Thread Luke Palmer
John Williams writes: > On Tue, 20 Apr 2004, Luke Palmer wrote: > > There. Now here's the important part: in order to *use* all this, you > > import whatever module defines it, and then say: > > > > class Dog { > > method foo (?$arg) is accessor { > > # accessor code here >

Re: A12: default accessors and encapsulation

2004-04-20 Thread John Williams
On Tue, 20 Apr 2004, Luke Palmer wrote: > There. Now here's the important part: in order to *use* all this, you > import whatever module defines it, and then say: > > class Dog { > method foo (?$arg) is accessor { > # accessor code here > } > } > > If that's not

Re: A12: default accessors and encapsulation

2004-04-20 Thread Luke Palmer
Mark J. Reed writes: > Let me just chime in with my support for John's basic idea. I would > definitely prefer that it be easy to arrange things such that > > $obj.foo = 'bar' > > winds up invoking a method on $obj with 'bar' as an argument, rather > than invoking a method on $obj that ret

RE: A12: default accessors and encapsulation

2004-04-20 Thread Austin Hastings
> -Original Message- > From: Mark J. Reed [mailto:[EMAIL PROTECTED] > > Let me just chime in with my support for John's basic idea. I would > definitely prefer that it be easy to arrange things such that > > $obj.foo = 'bar' > > winds up invoking a method on $obj with 'bar' as an a

Re: A12: default accessors and encapsulation

2004-04-20 Thread Matthew Walton
Mark J. Reed wrote: Let me just chime in with my support for John's basic idea. I would definitely prefer that it be easy to arrange things such that $obj.foo = 'bar' winds up invoking a method on $obj with 'bar' as an argument, rather than invoking a method on $obj that returns an lvalue to wh

Re: A12: default accessors and encapsulation

2004-04-20 Thread Mark J. Reed
Let me just chime in with my support for John's basic idea. I would definitely prefer that it be easy to arrange things such that $obj.foo = 'bar' winds up invoking a method on $obj with 'bar' as an argument, rather than invoking a method on $obj that returns an lvalue to which 'bar' is

Re: A12: default accessors and encapsulation

2004-04-20 Thread John Siracusa
On 4/20/04 1:25 AM, Luke Palmer wrote: > John Siracusa writes: >> The "will STORE" stuff covers the easy cases, but can I extend it all the >> way up to a name() that's a multimethod with a ton of optional args? I >> supposed you can (technically) do all of that with "will STORE", but it >> seems

Re: A12: default accessors and encapsulation

2004-04-20 Thread John Siracusa
On 4/19/04 10:04 PM, Damian Conway wrote: > John Siracusa wrote: >> I'd either like a way to more cleanly extend the default accessor's >> assignment behavior down the road (i.e. by just writing a new name() method, >> not by hacking away at STORE traits and adding private worker subs) or a way >>

Re: A12: default accessors and encapsulation

2004-04-20 Thread John Siracusa
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, an

Re: A12: default accessors and encapsulation

2004-04-20 Thread mark . a . biggar
> 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

Re: A12: default accessors and encapsulation

2004-04-19 Thread Larry Wall
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 me

Re: A12: default accessors and encapsulation

2004-04-19 Thread Damian Conway
John Siracusa wrote: > I'd either like a way to more cleanly extend the default accessor's > assignment behavior down the road (i.e. by just writing a new name() method, > not by hacking away at STORE traits and adding private worker subs) or a way > to auto-generate the slightly more "boring" def

Re: A12: default accessors and encapsulation

2004-04-19 Thread Luke Palmer
John Siracusa writes: > On 4/19/04 3:58 PM, Austin Hastings wrote: > >> I initially decide to accept the default accessors. > >> > >> $dog.name = 'Ralph'; > >> print $dog.age; > >> > >> This works well for a while, but then I decide to update Dog so that setting > >> the name also sets th

Re: A12: default accessors and encapsulation

2004-04-19 Thread John Siracusa
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 er

Re: A12: default accessors and encapsulation

2004-04-19 Thread John Siracusa
On 4/19/04 3:58 PM, Austin Hastings wrote: >> I initially decide to accept the default accessors. >> >> $dog.name = 'Ralph'; >> print $dog.age; >> >> This works well for a while, but then I decide to update Dog so that setting >> the name also sets the gender. >> >> $dog.name = 'Susi

RE: A12: default accessors and encapsulation

2004-04-19 Thread Austin Hastings
> -Original Message- > From: John Siracusa [mailto:[EMAIL PROTECTED] > Sent: Monday, 19 April, 2004 02:21 PM > To: Perl 6 Language > Subject: A12: default accessors and encapsulation > > > Let's say I have a class with some attributes: > >

Re: A12: default accessors and encapsulation

2004-04-19 Thread Juerd
John Siracusa skribis 2004-04-19 14:20 (-0400): > has $.gender is rw; > (...) > This works well for a while, but then I decide to update Dog so that setting > the name also sets the gender. > $dog.name = 'Susie'; # also sets $dog.gender to 'female' > How do I write such a name() method? Do

A12: default accessors and encapsulation

2004-04-19 Thread John Siracusa
Let's say I have a class with some attributes: class Dog; has $.name is rw; has $.age is rw; has $.gender is rw; I initially decide to accept the default accessors. $dog.name = 'Ralph'; print $dog.age; This works well for a while, but then I decide to update Dog so that