develooper Front page | perl.perl6.language.subs | Postings from August 2000

Re: RFC 118 (v1) lvalue subs: parameters, explicit assignment, andwantarray() changes

Thread Previous | Thread Next
From:
Hildo Biersma
Date:
August 28, 2000 02:31
Subject:
Re: RFC 118 (v1) lvalue subs: parameters, explicit assignment, andwantarray() changes
Message ID:
39AA3163.429B67C7@msdw.com
Nathan Torkington wrote:
> 
> Damian Conway writes:
> >    >   sub foo :lvalue { $foo }
> >    >   post foo { die if $foo == 5 }
> >    >
> >    >   eval {
> >    >     foo() = 5;
> >    >   };
> >
> > Postconditions on lvalue subs are not tested until the end of the complete
> > expression in which the sub is called.
> 
> But that won't change the fact that they are called *after* the lvalue
> has changed.  If they detect a problem, they can't unroll the change.
> 
> When you are passed the new value as an argument, you can die before
> a change is made.

Hold on - post conditions are not intended to veto a change, they're
intended to terminate the program if an assertion is invalid.  Hence it
should not matter if they run before or after assignment.

Given that the assertion should be "now this and that should be true",
and you may want to call validation methods as part of that assetion,
the implementation of the checks becomes vastly easier if they are
applied to the new state of the object, instead of the old state and a
set of proposed changes.

Hildo

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About