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
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
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
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
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,
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
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
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
@_ 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
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
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
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
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
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
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
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
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?
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
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
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'
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
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
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
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(
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]
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 )
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
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
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
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
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 )
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 );
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:
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(
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
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
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 =
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:
#
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
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.
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 =
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
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
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
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
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
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
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
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
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
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
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
52 matches
Mail list logo