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:

    sub foo ($arg1, $arg2, [EMAIL PROTECTED], =$x) {...}

    foo(6,9) = 42;       # the 42 gets passed to $x

That example uses a leading "=" for the "assigned" param (parallel to the leading "*" for the slurpy param), but I'm not crazy about it for various reasons (and =$x refers to iteration in other contexts). Perhaps it could be identified as "$x is assigned" -- but that doesn't look quite right to me either. However it's written, it would be simpler than having to use proxies.


-David

Reply via email to