2012/4/5 Anthony Ferrara ircmax...@gmail.com:
Why not just do:
function foo(callable $callback) {
$a = 0;
$callback();
$a = 1;
$callback();
}
function bar() {
foo(function() { echo 1; });
}
It's functionally the same, but doesn't have the stack magic.
Now, it won't
Rasmus,
I think you're missing the difference here. Let's look at an exception.
try {
doFoo();
throwsException();
doBar();
} catch (Exception $e) {
doBaz();
}
This is NOT the same as:
doFoo();
throwsException('doBaz');
doBar();
To emulate the exception using continuation
interesting, but this doesn't have anything in particular to do with
what I was talking about.
to the best of my understanding, an exception transfers control back
to the nearest calling code that has declared it is ready/willing/able
to resume control in the event that, somewhere up the
Rasmus,
What would that give you that a continuation passing paradigm
wouldn't? Why not tell the code what to call before you call it,
rather than bubbling up the stack (which then forces a fork of the
stack, as you need to partially unwind it, but keep track of what you
unwound for the resume).