I only looked at the first few slides. Don't understand the problem with the block variables? The current version seems clearer to me than the new proposal. Variables are visible in the block they have been defined in, what could be easier to understand? Probably I am missing something, though...
Yes I think so - your example will still print "after the block x is 5", but in that case that probably is what you would expect.
Maybe my head has just gone blank, but I cannot think of a way to get a local called 'x' inside that block that is in scope only within the block.
In Perl you would have done
my $x = 5;
foreach my $i in (1..5) {
my $x = $i;
...
}
And it would have given you a new 'block local' and left your original x alone, but I cannot think of how you can do the equivalent of 'my' in Ruby ...
Normally you'd expect the parameter of a block to be a new variable, not to grab a variable from another scope and use that instead. So the "expected" value is 4, since x = 4 on the first line.
You'd expect these two examples to output the same number:
You're right, and that is the behavior in Ruby 1.9.
I posted the example I did so that those unfamiliar with Ruby would see that the parent was a contrived example to use upto in that context. Sure it's awkward b/c it's not the intended semantics of the upto method, hence the ambiguity.
Maybe an ideal language would not introduce that sort of ambiguity... I personally slightly perfer the 1.9 syntax.