4 ms·
In the spirit of brainstorming, I think it’s cool to come up with some cases and ask, “what if?” In Yehuda’s article, he gives: withFile: function(block) {
by raganwald 15y ago
In the spirit of brainstorming, I think it’s cool to come up with some cases and ask, “what if?” In Yehuda’s article, he gives:
withFile: function(block) {
try {
var f = File.open(this.name, "r");
block(f);
} finally {
f.close();
}
}
This is interesting: “block” appears to be a “callable” object. How does the code know whether it will be a block or a function? Can you assign the block parameter to a variable? Pass it to another function? What about:
function firstClass (block) { return block; }
Can I do this? If so:
var thisIsaBlock = firstClass { |x| return x; }
And we’re off the rails. Or worse:
(function () {
var local = ‘0xDEADBEEF';
return firstClass { || local }
})()()
If I am reading the code example correctly and my inference holds, then either (a) you have to do a lot of escape analysis to make this work, or (b) you get lazy and allow programmers to pass blocks around but emit an exception if you try to call a block once its lambda environment has already returned.
I guess I need to read the whole proposal... I am sure this has been addressed.