On Wed, 12 Jun 2002 16:49:56 +0900
"Jean-Hugues ROBERT" <jean_hugues_robert / yahoo.com> wrote:

> Unfortunately I suspect that I would use "new/my/local" variables most of
> the time and that, as a result, my code would be cluttered with it.

Perhaps not so bad -- it appears to me that Ruby's scoping rules are similar
to C++'s, that is, a declared variable exists in the declaring scope and
those below, but not above, so you'd only need "new/my/local" when you
need to enforce block-local .

  int main(int atgc, char **argv)
  {
    int i = 3;
    int j = 10;

    for (i = 0; i < 10; i++)      // i references first declared i
      {
         j = 11;		  // j references first declared j
         printf("%d %d\n", i, j);
      }

    printf("%d %d\n", i, j);
  }

Change it to this:

  int main(int atgc, char **argv)
  {
    int i = 3;
    int j = 10;

    for (int i = 0; i < 10; i++)      // i local to this scope
      {
         int j = 11;		      // j local to this scope
	 int k = 42;		      // k local to this scope

	 for (int q = 10 ; q < 13 ; q++) 
	   {
	      printf("q is %d, k is %d\n", q, k); // k references previous 
						  // scope, q local
	   }

         printf("%d %d\n", i, j);
      }

    printf("%d %d\n", i, j);
  }

The difference is that Ruby has no explicit variable declaration like 
"int i" . 

This C++ style of scoping is why I haven't ever had a problem with 
block-declared variables referencing variables in the previous scope, but 
I've always considered (erroneously) that block parameters (|x,y|) were 
considered block local, with the || functioning as an explicit declaration 
of a new scope.

I guess then my preference would be that || declares block local, and that
we have another way of explicitly localizing block variables, like 

  foo = 12
  bar = 1
  baz = 2

  x.each { |foo|	# foo is explicitly local
    local bar = 10      # bar explicitly local
    baz = 3		# baz references previous scope
  }

As I discussed in my last post, I don't know if there are a lot of scripts 
that depend on block parameters referencing the previous scope, so I'm not 
sure how important backwards compatibility is for block paramters.

My feeling is that if we implemented the above scenario, the impact would 
be small enough to be worth it.

Just my $.02 . 

----------------------------------------------------------------------
| Jim Hranicky, Senior SysAdmin                   UF/CISE Department |
| E314D CSE Building                            Phone (352) 392-1499 |
| jfh / cise.ufl.edu                      http://www.cise.ufl.edu/~jfh |
----------------------------------------------------------------------