Does 'temp' operate on the value or on the container?  

The text starts, "The temp macro temporarily replaces the value of an existing 
variable..." and the description seems consistent with that.

   temp $*foo = 'foo';

The restore feature is generated by calling VAR($*foo).TEMP, and the method 
Scalar.TEMP can call its own STORE method.

But then there is the example

   temp &bar := sub {...};

That is, it uses binding rather than assignment, which applies to the container 

How can the container, which is Routine, know about the caller's &bar symbol?  
That is, &bar.TEMP, might be defined in Routine to be

   method TEMP ($self:)
    return sub { $self := $originalvalue }

it can rebind the $self argument which it closed over, but that will not affect 
the original caller's bar variable.  The aliasing of parameters to arguments is 
done by pointing to the same container.

Does anybody disagree with me?  That just doesn't compute.

Now what we really want here is to temporarily replace the meaning of the 
function call.  Routine already has the ability to be changed in-place, which 
is what .wrap does.  So we should simply allow .STORE to use the same ability, 
and then ordinary assignment, not binding, works.

   temp &bar = sub {...};  # use = not :=

The use of assignment calls the container's STORE, or whatever it will be named 
on Callable containers (there is no precedent in Perl 5's tie interface).  The 
use of temp will call Routine.TEMP for a closure, and it can work exactly like 
it does in a scalar: use its own STORE method to put back the saved value.

This change (just the one line of example) affects S06 under "Temporization".


Reply via email to