On Tue, 2 Dec 2003, David A. Black wrote:

> Hi --
>
> On Tue, 2 Dec 2003, John Carter wrote:
>
> > Perl has what may be an evil solution block locals.
> >
> > Certainly maximal surprise but Does What I Mean....
>
> [...]
>
> I'm sorry but I don't think I understand your post.  Are you asking
> about how 2.0 is going to handle scope?  I couldn't quite follow.

Now I reread my post I see I didn't make myself explicit. Sorry.

There has been debate on how to resolve the ugly problem of local's in
Ruby in V2.0.

The suggestion I'm making is add autovivification, with the rule that
if a block local needs autovivifying you probably mean it to have
larger than block scope. (Since there is an implicit "local_var =
SomeClass.new" before the block)

This makes for very terse code.

def histogram( enum)
  # <--- Implicit hash = Hash.new(0) here
  enum.each{|e| hash[e]+=1} # Hash autovivifies.
  # Since hash autovivified we expect it to be available
  # outside the block scope.
  hash.keys.sort{|a,b| hash[a]<=>hash[b]}.each do |k|
    puts "#{k}\t#{hash[k]}"
  end
end





John Carter                             Phone : (64)(3) 358 6639
Tait Electronics                        Fax   : (64)(3) 359 4632
PO Box 1645 Christchurch                Email : john.carter / tait.co.nz
New Zealand

A Million Monkeys can inflict worse things than just Shakespeare on
your system.