HaloO,

Dave Whipp wrote:
TSa wrote:

   class Length
   {
       has Num $.mm is rw = 0;
       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".

Why two assignments? $.mm is assigned only after resumption. From the
outside the ResumeProxy is used as '$obj.inch = 17' for assignment that
resumes the accessor and as 'say $obj.inch' as rvalue access that
garbage collects the invocation. The idea is that yield is a pseudo-
declarator. That is the above means

      method inch
      {
          my $inch = $.mm * 25.4;
          yield $inch;
          self.mm = $inch / 25.4;
      }

and might need a 'is rw' trait for better documentation.

Or did you mean

   my $obj = Length.new;

   $obj.inch = 17;
   $obj.mm = 100;

where I think the sequence of events is

  1) the invocation of .inch
  2) the yield of a ResumeProxy
  3) the call of infix:<=> with 17
  4) the resumption of the .inch invocation from 1
  5) the return of that assignment
  6) now the sequence is complete and the next
     assignment just overwrites the one from 1-5


Regards, TSa.
--

"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12  -- Srinivasa Ramanujan

Reply via email to