Greg Williams wrote:

> Interesting!  I have a few questions (meandering thoughts) though <g>
> 
> The example in the RFC gives:
> 
>      sub A{
>          my $A = shift;
>          return with;
>      };
> 
>      $context1 = A(3);
>      print "$context1";          # something like CONTEXT(0XF0GD0G)
>      print "$A" with $context1;  # prints 3
>      with $context1{print "$A"}; # same thing
> 
> This implies that &A is now something akin to a closure, correct?

I'm not sure how perl5 differnetiates btn closures and non-closures,
I thought it just defered certain aspects of scope destruction.


> That is to say, the meaning of C<my $A> becomes changed by the
> presence of C<return with;> so that $A is something in between a
> lexical scoped to &A and a lexical scoped around &A ({ my $A; sub A
> {} }).  $A is held in existence by the presence of the context
> object.  Presumably $A would 'go out of scope' and be destroyed at
> the same time as the associated context object?  This worries me, but
> I admit it's neat ;)

Yes, thus the warning about memory leaks.

> What is more worrying to me is this: with a C<no scope;> pragma, you
> can only go up /your/ scope.  Consider this:
> 
>      package Nasty;
>      my $context;
>      {
>          package Unsuspecting_Package;
>          $context = with;
>      }
>      use integer with $context;
> 
> Spooky action at a distance to be sure!  Also, integer (and others)
> is a compile time issue.  Using C<no scope> can be easily (it would
> appear) implemented for compile-time since it's merely another
> pragma.  On the other hand, C<with> strikes me as more of a run-time
> beast.  (at this point, I'm not sure if I have any idea of what I'm
> talking about, so excuse me if this has digressed into rambling :)


I agree.  If we were to allow run-time changing of aspects of basic reality
(I think we should, if we can, and we can)  then every time we do it
a flag gets set telling Perl to throw out its cache of jump tables and reread
the instructions.  Or the cache just gets thrown out.  What if 

        use integer

and similar pragmata  not only change aspects of eval() but also throw out all
the previous work.  In that context.

Or maybe it would have no effect at all:

        use real;
        sub pi_teration{
                # one iteration of some pi-finidng algo
                ...
        };
        use integer;
        # did I or did I not just hork my pi_iteration routine?


 
> So I like the idea of C<with>, but am not sure it is compeltely
> suitable for invoking pragmata such as integer.

it depends on what is and waht is not "within" a context.  That is
a question I would like to defer.


-- 
                          David Nicol 816.235.1187 [EMAIL PROTECTED]
                "After jotting these points down, we felt better."

Reply via email to