Re: [OT] accessors pragma

2003-09-18 Thread Piers Cawley
Damian Conway [EMAIL PROTECTED] writes: For what it's worth... Perl 6 classes will autogenerate accessors that return the underlying attribute itself as an lvalue: class DogTag { has $.name is public; has $.rank is public; has $.serial is

Re: [OT] accessors pragma

2003-09-18 Thread Steve Purkis
Well, So far there's a 55/45 split for chaining, so I'll release a preliminary version with: use accessors qw( foo bar baz ); # same as accessors::chained use accessors::classic qw( foo bar baz ); use accessors::chained qw( foo bar baz ); The last one will guarantee

Re: [OT] accessors pragma

2003-09-17 Thread Richard Clamp
On Wed, Sep 17, 2003 at 09:47:43AM +0100, Tom Insam wrote: At 17:59 +0100 2003/09/16, Steve Purkis wrote: Secondly, with the current implementation an 'undef' argument will trigger a set for both 'classic' and 'chained' accessors: $book-author($a); # still sets when $a = undef

Re: [OT] accessors pragma

2003-09-17 Thread Tom Insam
At 17:59 +0100 2003/09/16, Steve Purkis wrote: Secondly, with the current implementation an 'undef' argument will trigger a set for both 'classic' and 'chained' accessors: $book-author($a); # still sets when $a = undef How? I can't see how that would work.. -- .tom

Re: [OT] accessors pragma

2003-09-17 Thread Michel Rodriguez
On Tue, 16 Sep 2003, Steve Purkis wrote: On Tuesday, September 16, 2003, at 02:53 pm, Andy Wardley wrote: On the other hand, I find it quite acceptable to have get_foo() that returns the foo, and set_foo($new_value) which sets the new value for foo and returns the object. In this case,

Re: [OT] accessors pragma

2003-09-17 Thread Robin Berjon
Richard Clamp wrote: @_ will still have an element in it after shifting off $self, so the old favourite: sub foo { my $self = shift; if (@_) { $self-{foo} = shift; } $self-{foo}; # or $self; } Will still have something to assign. While I'm not a golfer and am usually

Re: [OT] accessors pragma

2003-09-17 Thread Tom Insam
At 10:00 +0100 2003/09/17, Richard Clamp wrote: How? I can't see how that would work.. @_ will still have an element in it after shifting off $self, so the gaaah. ok, I can see that. -- .tom

Re: [OT] accessors pragma

2003-09-17 Thread David Cantrell
On Wed, Sep 17, 2003 at 11:21:50AM +0200, Robin Berjon wrote: sub foo { @_==2 ? shift-{foo} = shift : shift-{foo} } ^ ^ Is the order of evaluation of those two shift()s guaranteed? -- Lord Protector David Cantrell | http://www.cantrell.org.uk/david

Re: [OT] accessors pragma

2003-09-17 Thread David Wright
@_ will still have an element in it after shifting off $self, so the old favourite: sub foo { my $self = shift; if (@_) { $self-{foo} = shift; } $self-{foo}; # or $self; } Will still have something to assign. While I'm not a golfer and am

Re: [OT] accessors pragma

2003-09-17 Thread Paul Makepeace
Je 2003-09-17 10:21:50 +0100, Robin Berjon skribis: sub foo { @_==2 ? shift-{foo} = shift : shift-{foo} } sub foo { @_==2 ? $_[0]-{foo} = $_[1] : $_[0]-{foo} } Probably marginally quicker, and doesn't leave that niggly feeling about which shift might be evaluated in what order in a future

Re: [OT] accessors pragma

2003-09-17 Thread Robin Berjon
David Cantrell wrote: On Wed, Sep 17, 2003 at 11:21:50AM +0200, Robin Berjon wrote: sub foo { @_==2 ? shift-{foo} = shift : shift-{foo} } ^ ^ Is the order of evaluation of those two shift()s guaranteed? I thought about that as I was writing it, I normally

Re: [OT] accessors pragma

2003-09-17 Thread Robin Berjon
Nicholas Clark wrote: There's just been a long thread about this on p5p. I think that not really is the current answer, and it's proved impossible to cleanly write down what the order of evaluation is. In the above line, they evaluate right to left, because the RHS of the assignment is being

Re: [OT] accessors pragma

2003-09-17 Thread Michel Rodriguez
On Wed, 17 Sep 2003, Paul Makepeace wrote: Je 2003-09-17 10:21:50 +0100, Robin Berjon skribis: sub foo { @_==2 ? shift-{foo} = shift : shift-{foo} } sub foo { @_==2 ? $_[0]-{foo} = $_[1] : $_[0]-{foo} } Probably marginally quicker, and doesn't leave that niggly feeling about which

Re: [OT] accessors pragma

2003-09-17 Thread Robin Berjon
David Wright wrote: sub foo { @_==2 ? shift-{foo} = shift : shift-{foo} } Why bother shifting at all then? sub foo { @_==2 ? $_[0]-{foo} = $_[1] : $_[0]-{foo} } Because it's cuter and easier to type. Oh, and it's nigh impossible to tell them apart: === use Benchmark qw(timethese cmpthese); my

Re: [OT] accessors pragma

2003-09-17 Thread Nicholas Clark
On Wed, Sep 17, 2003 at 11:58:27AM +0200, Robin Berjon wrote: Nicholas Clark wrote: There's just been a long thread about this on p5p. I think that not really is the current answer, and it's proved impossible to cleanly write down what the order of evaluation is. In the above line, they

Re: [OT] accessors pragma

2003-09-17 Thread Shevek
On Wed, 17 Sep 2003, Robin Berjon wrote: Richard Clamp wrote: @_ will still have an element in it after shifting off $self, so the old favourite: sub foo { my $self = shift; if (@_) { $self-{foo} = shift; } $self-{foo}; # or $self; } Will

Re: [OT] accessors pragma

2003-09-17 Thread Shevek
On Wed, 17 Sep 2003, Robin Berjon wrote: David Cantrell wrote: On Wed, Sep 17, 2003 at 11:21:50AM +0200, Robin Berjon wrote: sub foo { @_==2 ? shift-{foo} = shift : shift-{foo} } ^ ^ Is the order of evaluation of those two shift()s guaranteed?

Re: [OT] accessors pragma

2003-09-17 Thread Mark Fowler
On Tue, 16 Sep 2003, Steve Purkis wrote: There are two popular styles of accessor I'd like to support: # classic: print I set foo! if $obj-foo( $a_value ); # chaining: $obj-foo( $a_value ) -bar( $another_value ); Firstly, I prefer proper exceptions when

Re: [OT] accessors pragma

2003-09-17 Thread Steve Purkis
On Wednesday, September 17, 2003, at 02:49 am, Randal L. Schwartz wrote: Steve == Steve Purkis [EMAIL PROTECTED] writes: Steve Hi all, Steve With the help of others, I've been bashing out an 'accessors' pragma[1]: Steve use accessors qw( foo bar baz ); Steve There are two popular styles of

Re: [OT] accessors pragma

2003-09-17 Thread Steve Purkis
On Wednesday, September 17, 2003, at 02:50 am, Randal L. Schwartz wrote: Steve == Steve Purkis [EMAIL PROTECTED] writes: I've seen: print Old version of foo was . $obj-foo( $new_foo ); (gtk, I think), and print New version of foo is now . $obj-foo( $new_foo ); Steve This is the 'classic'

Re: [OT] accessors pragma

2003-09-17 Thread Shevek
On Wed, 17 Sep 2003, Mark Fowler wrote: On Tue, 16 Sep 2003, Steve Purkis wrote: That having been said, are you aware of Want? If you want to do the above you can do something like this: use Want; if (want('OBJECT')) { $self-_set_foo($_[0]); return $self

Re: [OT] accessors pragma

2003-09-17 Thread Steve Purkis
On Wednesday, September 17, 2003, at 10:08 am, Michel Rodriguez wrote: On Tue, 16 Sep 2003, Steve Purkis wrote: On Tuesday, September 16, 2003, at 02:53 pm, Andy Wardley wrote: On the other hand, I find it quite acceptable to have get_foo() that returns the foo, and set_foo($new_value) which

Re: [OT] accessors pragma

2003-09-17 Thread Steve Purkis
On Wednesday, September 17, 2003, at 10:48 am, Paul Makepeace wrote: Je 2003-09-17 10:21:50 +0100, Robin Berjon skribis: sub foo { @_==2 ? shift-{foo} = shift : shift-{foo} } sub foo { @_==2 ? $_[0]-{foo} = $_[1] : $_[0]-{foo} } Probably marginally quicker, and doesn't leave that niggly

Re: [OT] accessors pragma

2003-09-17 Thread Sam Vilain
On Wed, 17 Sep 2003 11:55, Steve Purkis wrote; Hmm, that's very similar in spirit to the 'classic' form. Will generated accessors be overridable? I can see how 'given' would be useful, but what if I wanted to say this: $grunt.name( Patton ) .rank(

Re: [OT] accessors pragma

2003-09-17 Thread Robin Berjon
Shevek wrote: On Wed, 17 Sep 2003, Robin Berjon wrote: sub foo { @_==2 ? shift-{foo} = pop : shift-{foo} } This is semantically different, and therefore not an appropriate answer. Semantically different from what, and an appropriate answer to what? It DTRT. -- Robin Berjon [EMAIL PROTECTED]

Re: [OT] accessors pragma

2003-09-17 Thread Steve Purkis
On Wednesday, September 17, 2003, at 11:38 am, Mark Fowler wrote: On Tue, 16 Sep 2003, Steve Purkis wrote: There are two popular styles of accessor I'd like to support: # classic: print I set foo! if $obj-foo( $a_value ); # chaining: $obj-foo( $a_value )

Re: [OT] accessors pragma

2003-09-17 Thread Robin Berjon
Shevek wrote: On Wed, 17 Sep 2003, Robin Berjon wrote: Shevek wrote: On Wed, 17 Sep 2003, Robin Berjon wrote: sub foo { @_==2 ? shift-{foo} = pop : shift-{foo} } This is semantically different, and therefore not an appropriate answer. Semantically different from what, and an appropriate answer to

Re: [OT] accessors pragma

2003-09-17 Thread Shevek
On Wed, 17 Sep 2003, Robin Berjon wrote: Shevek wrote: On Wed, 17 Sep 2003, Robin Berjon wrote: sub foo { @_==2 ? shift-{foo} = pop : shift-{foo} } This is semantically different, and therefore not an appropriate answer. Semantically different from what, and an appropriate answer to

Re: [OT] accessors pragma

2003-09-17 Thread Steve Purkis
On Wednesday, September 17, 2003, at 12:34 pm, Sam Vilain wrote: [snip!] Either of these are good IMHO: $class-set_attribute(value); $class-attribute = value; In both cases, it is 100% clear that the `$class' object it having its `attribute' member updated. The first example up there is

Re: [OT] accessors pragma

2003-09-17 Thread Damian Conway
Steve Purkis asked: Will generated accessors be overridable? Indeed they will. If the class has an explicitly declared method of the same name, that method will prevent the accessor from being generated. And, of course, accessors are just methods, so derived classes can override them in the

[OT] accessors pragma

2003-09-16 Thread Steve Purkis
Hi all, With the help of others, I've been bashing out an 'accessors' pragma[1]: use accessors qw( foo bar baz ); There are two popular styles of accessor I'd like to support: # classic: print I set foo! if $obj-foo( $a_value ); # chaining: $obj-foo( $a_value )

Re: [OT] accessors pragma

2003-09-16 Thread Tom Insam
At 13:09 +0100 2003/09/16, Steve Purkis wrote: Hi all, With the help of others, I've been bashing out an 'accessors' pragma[1]: use accessors qw( foo bar baz ); There are two popular styles of accessor I'd like to support: # classic: print I set foo! if $obj-foo( $a_value );

Re: [OT] accessors pragma

2003-09-16 Thread Steve Purkis
On Tuesday, September 16, 2003, at 01:27 pm, Tom Insam wrote: At 13:09 +0100 2003/09/16, Steve Purkis wrote: Hi all, With the help of others, I've been bashing out an 'accessors' pragma[1]: use accessors qw( foo bar baz ); There are two popular styles of accessor I'd like to support:

Re: [OT] accessors pragma

2003-09-16 Thread Shevek
On Tue, 16 Sep 2003, Steve Purkis wrote: Hi all, With the help of others, I've been bashing out an 'accessors' pragma[1]: use accessors qw( foo bar baz ); There are two popular styles of accessor I'd like to support: # classic: print I set foo! if $obj-foo(

Re: [OT] accessors pragma

2003-09-16 Thread David Cantrell
On Tue, Sep 16, 2003 at 02:18:57PM +0100, Steve Purkis wrote: On Tuesday, September 16, 2003, at 01:27 pm, Tom Insam wrote: Having said that, I like chaining. Duly noted. So do I. I have recently fallen in love with Scalar::Properties (thanks Marcel!) and do stuff like ... return

Re: [OT] accessors pragma

2003-09-16 Thread Robin Berjon
Shevek wrote: This whole chained accessors thing is a definite perl-ism and will do you no favours with people for whom Perl is not a primary language. Possible return values for write-accessors: true/false undef/error message the previous value the new value [I would never have considered the

Re: [OT] accessors pragma

2003-09-16 Thread David Cantrell
On Tue, Sep 16, 2003 at 02:44:25PM +0100, Shevek wrote: This whole chained accessors thing is a definite perl-ism and will do you no favours with people for whom Perl is not a primary language. I see similar method chaining in Java. poing =

Re: [OT] accessors pragma

2003-09-16 Thread Steve Purkis
On Tuesday, September 16, 2003, at 02:44 pm, Shevek wrote: On Tue, 16 Sep 2003, Steve Purkis wrote: Hi all, With the help of others, I've been bashing out an 'accessors' pragma[1]: use accessors qw( foo bar baz ); There are two popular styles of accessor I'd like to support: #

Re: [OT] accessors pragma

2003-09-16 Thread Andy Wardley
Steve Purkis wrote: # chaining: $obj-foo( $a_value ) -bar( $another_value ); I recognise how useful this can be but I'm not a fan of it. IMHO, the foo() method of an object should return the foo of the object. It shouldn't magically switch to returning the object

Re: [OT] accessors pragma

2003-09-16 Thread Paul Makepeace
Je 2003-09-16 15:40:45 +0100, David Cantrell skribis: On Tue, Sep 16, 2003 at 02:44:25PM +0100, Shevek wrote: This whole chained accessors thing is a definite perl-ism and will do you no favours with people for whom Perl is not a primary language. I see similar method chaining in Java.

Re: [OT] accessors pragma

2003-09-16 Thread Shevek
On Tue, 16 Sep 2003, David Cantrell wrote: On Tue, Sep 16, 2003 at 02:44:25PM +0100, Shevek wrote: This whole chained accessors thing is a definite perl-ism and will do you no favours with people for whom Perl is not a primary language. I see similar method chaining in Java. poing =

Re: [OT] accessors pragma

2003-09-16 Thread Steve Purkis
On Tuesday, September 16, 2003, at 03:37 pm, David Cantrell wrote: On Tue, Sep 16, 2003 at 02:18:57PM +0100, Steve Purkis wrote: On Tuesday, September 16, 2003, at 01:27 pm, Tom Insam wrote: Having said that, I like chaining. Duly noted. So do I. I have recently fallen in love with

Re: [OT] accessors pragma

2003-09-16 Thread Paul Makepeace
Je 2003-09-16 15:37:49 +0100, David Cantrell skribis: return 0-reason(ERR_BAD_PARAM)-details('foo') unless($params{foo} $params{foo}-isa('Foo')); WTF is that?! If I saw this in a forest I'd shoot it first, assuming it was more likely going to kill me than not. P -- Paul Makepeace

Re: [OT] accessors pragma

2003-09-16 Thread Shevek
On Tue, 16 Sep 2003, Paul Makepeace wrote: Je 2003-09-16 15:37:49 +0100, David Cantrell skribis: return 0-reason(ERR_BAD_PARAM)-details('foo') unless($params{foo} $params{foo}-isa('Foo')); WTF is that?! If I saw this in a forest I'd shoot it first, assuming it was more likely going to

Re: [OT] accessors pragma

2003-09-16 Thread Steve Purkis
On Tuesday, September 16, 2003, at 02:53 pm, Andy Wardley wrote: Steve Purkis wrote: # chaining: $obj-foo( $a_value ) -bar( $another_value ); I recognise how useful this can be but I'm not a fan of it. IMHO, the foo() method of an object should return the foo of the

Re: [OT] accessors pragma

2003-09-16 Thread David Cantrell
Shevek wrote: On Tue, 16 Sep 2003, David Cantrell wrote: I see similar method chaining in Java. poing = foo.convert_to_bar().do_stuff_to_object().convert_to_string(); In this case, I don't see that foo.convert_to_bar() is returning foo. I don't claim that method chaining is wrong. I claim that

Re: [OT] accessors pragma

2003-09-16 Thread David Cantrell
Paul Makepeace wrote: Je 2003-09-16 15:37:49 +0100, David Cantrell skribis: return 0-reason(ERR_BAD_PARAM)-details('foo') unless($params{foo} $params{foo}-isa('Foo')); WTF is that?! If I saw this in a forest I'd shoot it first, assuming it was more likely going to kill me than not. Something

Re: [OT] accessors pragma

2003-09-16 Thread Shevek
On Tue, 16 Sep 2003, David Cantrell wrote: Paul Makepeace wrote: Je 2003-09-16 15:37:49 +0100, David Cantrell skribis: return 0-reason(ERR_BAD_PARAM)-details('foo') unless($params{foo} $params{foo}-isa('Foo')); WTF is that?! If I saw this in a forest I'd shoot it first, assuming it

Re: [OT] accessors pragma

2003-09-16 Thread David Cantrell
Shevek wrote: On Tue, 16 Sep 2003, David Cantrell wrote: Paul Makepeace wrote: WTF is that?! If I saw this in a forest I'd shoot it first, assuming it was more likely going to kill me than not. Something which makes perfect sense when read in conjunction with the documentation. What, exactly, do

Re: [OT] accessors pragma

2003-09-16 Thread Adrian Howard
On Tuesday, Sep 16, 2003, at 13:09 Europe/London, Steve Purkis wrote: [snip] If you have a preference here, let me know. [snip] I quite like chaining myself - but then I like Smalltalk too :-) Adrian

Re: [OT] accessors pragma

2003-09-16 Thread Damian Conway
For what it's worth... Perl 6 classes will autogenerate accessors that return the underlying attribute itself as an lvalue: class DogTag { has $.name is public; has $.rank is public; has $.serial is readonly; has @.medals

Re: [OT] accessors pragma

2003-09-16 Thread Randal L. Schwartz
Steve == Steve Purkis [EMAIL PROTECTED] writes: I've seen: print Old version of foo was . $obj-foo( $new_foo ); (gtk, I think), and print New version of foo is now . $obj-foo( $new_foo ); Steve This is the 'classic' style I had in mind. Then your naming is odd. I thought classic