[% setvar title caller->eval BLOCK %]

This file is part of the Perl 6 Archive

Note: these documents may be out of date. Do not use as reference!

To see what is currently happening visit http://www.perl6.org/


caller->eval BLOCK


  Maintainer: David Nicol <perl6rfc@davidnicol.com>
  Date: 28 Sep 2000
  Mailing List: perl6-language@perl.org
  Number: 339
  Version: 1
  Status: Developing


caller is extended to allow complete access to the "call frame" of the current subroutine call.


Some new syntax is introduced, involving the caller keyword, that allows evaluation of expressions from the point of view of the situation from which the current method was called. After thinking about it for a while I think

	caller->eval EXPRESSION;

would work well, with the prototype and semantics of this construction being identical to regular eval, except that resolution of names is done as if the eval was happening where the call happened.

Neat tricks become possible by directly accessing the immediate symbol table of the calling context.

  • caller->eval and the hastily destructing return
  • Also, if we adopt <a href=www.mail-archive.com> a hastily destructing return </a> (or even if we don't, but easier if we do) we might be able to break out of loops in the calling context, for instance

    	return caller->eval{return undef} if $WeAreDone;

    would, in the case of $WeAreDone being true, make a first pass over the expression to be returned, incrementing the reference counts therein, in this case evaluating "caller" for a value, but not running its eval method, then destroy the subroutine context (except for rescued values, which there are none of here) and then evaluate the returned expression.

    In this case, the returned expression is a flow control directive, which will be followed, returning an undefined value from the calling routine.

    In this case, prefixing caller-eval> with return might be optional.


    caller is altered to return a tied scalar that stringifies to the "caller's package name" if defined, to match perl5. This object has some other methods though, in particular an "eval" method which is described above.

    we will still need to keep track of the names of lexical variables that have been lost to packed offset optimizations, in case they get referred to by name from within a called function.

    If caller-eval> contains flow control directives which take us out of the calling context, the current context must be destroyed


    perldoc -f caller

    How To Implement Tail Recursion: www.mail-archive.com