Created
January 28, 2012 00:28
-
-
Save kriskowal/1691779 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function foo() { | |
| bar({|x| | |
| return 10; | |
| }); | |
| } | |
| function bar(block) { | |
| block(); | |
| block(); // we should never get here. how? | |
| } | |
| foo(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 10 foo(); // stack: [] | |
| 2 bar({|x| return 10}) // stack: [foo] | |
| 7 block() // stack: [foo, bar] | |
| 3 return 10 // stack: [foo, bar, block] | |
| … |
Author
Author
@dherman I think that finally will have to suffice. It would be an information/capability leak for an intermediate stack frame to be able to observe the return value in a parent lexical scope. MarkM would kill me for suggesting it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@dherman Right. The
finallyclause might be enough.I did not mean to imply that you could fabricate a
ReturnValueexception and throw it, causing a return from the first parent scope. I mean that areturnin a block lambda would construct aReturnValueexception with a read-onlyvalue(at least), add it to a side-table.Then
foowould implicitly catch the exception and convert aReturnValue.valueinto a return value only if the exception in the side-table maps tofoo.This would make it possible for an intermediary to observe the exception in a catch block, rethrow it, or throw a different exception. It would not give the ability to return an arbitrary value from an arbitrary parent scope.