HaloO,

I wrote:
I wonder if that couldn't simply be

     method attr is rw
     {
        return self.blahh;
     }

Or am I missing something?

Hmm, I forget something along the lines of

   method attr ($rhs)
   {
      if $rhs > 10 { return self.blahh }
      else         { return self.blubb }
   }

which might be with my concept of equality of object as instance of
a class and of a method invocation as "instance of a method class"
written as

   method attr is rw
   {
       yield $rhs; # coroutine like return
       # we resume here after assignment
       if $rhs > 10 { self.blahh = $rhs}
       else         { self.blubb = $rhs}
   }

The yield there will return the current invocation of the method
as assignment proxy. The assignment operator needs to be overloaded
for this type something like this

   multi sub infix:<=>(AssignmentProxy $lhs, $rhs)
   {
      $lhs.resume($rhs);
   }

With this in place an AssignmentProxy might actually work as rvalue,
too. Thus one can drop the 'is rw' from attr and all the magic is in
the yield declarator/statement.

   class Obj
   {
       has $.foo = 'foo';
       has $.blubb = 'blubb';
       has $.blahh = 'blahh';
       method attr
       {
          yield $rhs = self.foo;

          if $rhs > 10 { self.blahh = $rhs}
          else         { self.blubb = $rhs}
       }
   }

   my $x = Obj.new;

   say $x.attr; # prints 'foo'

   $x.attr = 42;

   say $x.blahh; # prints 42

So the return type of a yield might actually be ResumeProxy:

   sub foo ($x, $y)
   {
       my $count = 0;
       while $count < $y - $x { yield ++count; }
       yield -1 while True;
   }

   say foo(7,23).resume.resume; # prints 3

   my $f = foo(10,15);

   say $f; # prints 1

   $f.resume while $f != -1;

   say $f; # prints -1

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