1 Jun 2008 14:06
Re: assignable mutators (S06/Lvalue subroutines)
David Green <david.green <at> telus.net>
2008-06-01 12:06:05 GMT
2008-06-01 12:06:05 GMT
On 2008-May-27, at 9:40 am, Dave Whipp wrote:
> TSa wrote:
>> method inch
>> {
>> yield $inch = $.mm * 25.4;
>> self.mm = $inch / 25.4;
>> }
>> Would you regard that as elegant?
>
> That looks functionally incorrect to my eyes: if the caller resumes
> at the time of the "yield" statement, and immediately assigns a new
> value to the "mm" attribute, then there is a race between the two
> updates to "mm".
It seems overly complex to me, but perhaps I'm missing good reasons
for such an approach. I see lvalue subs mainly as syntactic sugar:
foo(42); # arg using normal syntax
foo <== 42; # arg using feed syntax
foo = 42; # arg using assignment syntax
Feeds are a way of passing values to a function, but work like
assignment when used on a variable; assignment is a way of giving a
value to a variable, so it should work like passing args when used on
a function. Then you can easily do whatever you want with it.
In fact, it could work just like a feed, and pass values to the slurpy
params, but I think assignment is special enough to be worth treating
separately. Maybe something like:
(Continue reading)
RSS Feed