From: ahoward Date: 2003-01-31T01:02:35+09:00 Subject: Re: Local variables & blocks On Thu, 30 Jan 2003, Yukihiro Matsumoto wrote: > Describe your feeling and ideas. please also see prior threads. summary : there is only ONE common case of people wanting to export variable from a block, and that is that one of some type of accumulator living on beyond the scope of a block, the a = [] loop do ... a << method ... end situation. i'm not saying that's not a good reason to do something, or that there are not other situation where it might make good sense to export a variable, but it is the exception, _not_ the rule that why i suggested the _exceptional_ case of loop do export a = [] ... a << method ... end export -> declare/define, once only, a variable in the parent's scope (dynamic) as solving that problem. though someone pointed out it was more typing than the current method of 'a = []' before the loop i really _do_ think this idiom could lead to more elegant _looking_ code whose intent is clearer. > This is why I post. What kind of situations do you think this change does > not cover properly? * Threads * GC * Comfort in knowing a module writer cannot fill your namespace up inadvertantly * Need to track memory usage in blocks : (2 << 15).times do |i| eval "leak_#{i} = 'a big fat leak' * (2 << 16)" end but perhaps there is a was around these issues i've overlooked (very likey - i' not that smart!) ;-) -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ahoward@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================