in reply to Re^4: Tim O'Reilly on Perl
in thread Tim O'Reilly on Perl

Will we have lvalue methods in Perl 6? Because that's what really bugs me, about Perl 5 OO.
$obj->SetProperty("something");
is just ugly, compared to the shiny elegance of
$obj->Property = "something";


holli, /regexed monk/

Replies are listed 'Best First'.
Re^6: Tim O'Reilly on Perl
by eric256 (Parson) on Jul 14, 2005 at 14:14 UTC

    It does indeed have that already.

    use v6; class test { has $.Property; } my $testing = new test; $testing.Property = 5; $testing.Property.say;

    I beleive that it actualy uses a Proxy object with lvalue attributes, but don't quote me on that. ;)


    ___________
    Eric Hodges

      Gah, ambiguous indirect object notation went away in Perl 6. Mark the invocant explicitly:

      my $testing = new test:;

      Or make a method call look like a method call:

      my $testing = test.new()

        Since the objects have no obvious public method new it makes more sense (to me) to call them in a magical sort of way. I don't see what adding the : to the end of the name does for anything. It certainly doesn't make it clearer. However new Object is pretty standard across many languages while your two examples are not. I would agree with using your second form on everything except new. It reads easier when you say $x is a (=) new Object.


        ___________
        Eric Hodges
Re^6: Tim O'Reilly on Perl
by blazar (Canon) on Jul 14, 2005 at 14:11 UTC
    You bet you will have them! Only such a method will be spelled 'is rw'. Well, until Larry changes his mind on this...
Re^6: Tim O'Reilly on Perl
by tlm (Prior) on Jul 17, 2005 at 20:14 UTC

    Is there something wrong with Perl 5's lvalue attribute? As far as I can tell, it produces rather functional lvalue accessors:

    package Foo; sub foo : lvalue { my $self = shift; warn "Only first argument to method foo is used" if @_ > 1; $self->{ foo } = shift if @_; $self->{ foo }; } my $x = bless +{}, 'Foo'; $x->foo = 3; print $x->foo, "\n"; $x->foo++; print $x->foo, "\n"; $x->foo += 6; print $x->foo, "\n"; __END__ 3 4 10
    I know that user-defined functions with the lvalue attribute, in general, will give wrong results in the debugger, but that's only a problem for those weenies who use the debugger ;-) (Plus, there are good ways around this.)

    the lowliest monk

      Yeah. The problem with them is one can't check the value before it is set. I would like to have something like
      sub foo : get { my $self = shift; return $self->{_foo}; } sub foo : set { my $self = shift; my $value = shift; die "foo is a integer field!\n" unless $value =~ /[+-]?[0-9]+/; $self->{_foo} = $value; }


      holli, /regexed monk/
        The problem with them is one can't check the value before it is set.

        Oh, but you can. I addressed that in To Validate Data In Lvalue Subs. The Constrained package from that node turned out to have lots of other uses, too. It's now called Tie::Constrained on CPAN.

        After Compline,
        Zaxo