On Thu, Jan 30, 2003 at 10:30:47PM +0900, Yukihiro Matsumoto wrote:
> Hi,
> 
> In message "Re: Local variables & blocks"
>     on 03/01/30, "Robert Klemme" <bob.news / gmx.net> writes:
> 
> |Just to make sure: From what I read in this thread there are quite some
> |situations which could be problematic with exporting a variable from a
> |block to its enclosing scope. Are all these situations properly regarded?
> |
> |I still feel a unwary about this change...
> 
> Describe your feeling and ideas.  This is why I post.  What kind of
> situations do you think this change does not cover properly?


I think I preferred the solution with ':='. Even though I was reluctant
at first, I now feel it is cleaner because I don't really like 

> * no other way to make block local variables

that much.

Idiotic code:
 ...
 10000.times { |i| (a ||= []) << i } # handy, for I'm not doing 'a = []'
				     # first, but slower because I compare
                                     # on each iteration
 				     # if I use 'a=[]' before, one of
 				     # the advantages is lost
 a.map! do |i|  
	tmp = some_slow_func_of(i)   # I only want to compute this once
				     # per iteration
	[tmp, tmp]                   # or anything that uses tmp more
                                     # than once
 end 

 # tmp is alive here.
 # Now imagine it is something huge... There's no way to tell Ruby it
 # won't be needed in the future so it is GC'ed, unless I do
 tmp = ''  # ugly
 # but I wanted it to be local!

Plus if I change things inside a block I have to check things all
around, both before and after...

BEFORE
  ... some code (1) ...
  ... do
# if I change things in the block, I've got to be sure I'm not altering
# one of the variables in the outer scope => gotta check in (1)      
  end
  ... some code(2) ...

AFTER
  ... some code (1) ...
  ... do
	# now have to see 'variable-wise' if I'm breaking things in (2)
  end  
  ... some code(2) ...

It is hard to believe that we never really needed locals but as
arguments...

-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Make it idiot-proof, and someone will breed a better idiot.
	-- Oliver Elphick