On Fri, Oct 04, 2002 at 10:58:07AM +0900, Gavin Sinclair wrote:
> I've cannibalised discussion from the "Bugs" thread.  I hope it is a service to
> the community to reopen this.  The poll on RubyGarden votes "make 'em all
> local", closely followed by "leave it unchanged".  Yet the "problem" keeps
> coming up, and the most sensible solution (in my mind) is not represented in
> the poll.
> 
> I think it makes sense to explicitly mark *external* variables, as block-local
> variables (parameters, in fact) would be the norm.
> 
> Thus, if 'a' and 'c' are regular parameters and 'b' is an external variable,
> then one could write
> 
>   collection.each do |a,:b,c|
>     ...
>   end
> 
> or
> 
>   collection.each do |a,b,c|
>     external b
>     ...
>   end
> 
> I'm not sure which of the above I prefer.  One should optimise for the common
> case.
> 
> I'd like to put a question to the audience :)  Does anyone actually have a need
> to use non-local block parameters?  Ever?

I've asked this before but can't recall any answers. How would one
do the following without non-local block params:

a = [1.1, 3.14, 2.7, 5.15]
sum = 0.0
a.each { |elem| sum += a }

Personally, I like accessing external scope by default. C behaves similiarly:
#include <stdio.h>

int main()
{
	int a = 42;
	int b = 55;
	
	printf("a: %d b: %d\n", a, b );

	{
		int a = 33; /* define a as local scope to this block*/
		printf("a: %d b: %d\n", a, b );
	}
}

Gives you
a: 42 b: 55
a: 33 b: 55

-- 
Alan Chen
Digikata LLC
http://digikata.com