Hey all. This is going to seem like a kind of wierd suggestion (it isn't
yet fleshed out enough to call a proposal), but...
First, let's define a context as everything needed to goto a point. Thus,
it's a mixture of a pointer into the instruction stream (internals people,
please forgive me for abusing your vocabulary) and a variable stash. It's
also needed to: call a closure, return into a started coroutine, go up and
down the call-stack when debuging, introspect, local()ize variables, and
probably a bunch of other things.
So, how should perl code be able to get to them?
1) A function that returns the current context.
$current_context = context();
2) A function that returns the context for a closure.
$closures_context = context(\&closure);
3) A function that returns the stack of currently executing contexts.
@current_stack = context();
(Note: I think that the current context should be first on the list, then
the caller thereof, unto the nth degree.)
[Note that context() has a superset of the capibilities of caller(). I
don't take this to be reason to remove caller().]
Now, what can a context object do?
1) Execute arbitrary code from within that context: $context->eval(STRING),
or $context->eval(CODEREF).
2) Find the value of a variable as seen from within that context...
$$context->{scalar}/@$context->{array}? I'm not certian of the synthax on
this one. Note that it's equivlent to $context->eval("$scalar").
3) Goto the context: $context->goto;
4) Change the value of a variable as seen from within that context...
$context->$scalar = 42? That synthax isn't meaningful in existing perl, but
feels natural... Note that this synthax should be the lvalue equiv of 2.
5) [Returning to a started coroutine is gotoing into it]
6) Everything that caller() can do -- give the package, filename,
linenumber, type, label.
Here, type and label aren't quite what eval gives...
type is one of require, plain (for plain { } blocks), do, eval, try, sort,
etc, etc (basicly, every op that takes a BLOCK), and label is the label of
the loop, or name of the sub (if non-anonymous).
What do you guys think?
-=- James Mastros