On Fri, 14 Oct 2005, Christian Neukirchen wrote:

> "David A. Black" <dblack / wobblini.net> writes:
>
>> Hi --
>>
>> On Fri, 14 Oct 2005, Gyoung-Yoon Noh wrote:
>>
>>> +1
>>>
>>> collection.each : (foo="bar") { puts foo }
>>>
>>> It looks like 'when condition : expression' branch in
>>> 'case' statement.
>>
>> But why would you want a method call and argument list and block to
>> look like when condition : expression ?  There's no "then" meaning to
>> it.
>
> Read the : as "do".  When x is one, do... For every item of the
> collection, do...
>
> I think the :(){} stuff is the nicest looking approach as of now, but
> I wouldn't use it when ordinary {||} is enough.

it all seems like a __lot__ of coding for someone when one can simply

   harp:~ > cat a.rb
   collection = [ 4, nil, 2 ]
   collection.each{|foo| foo ||= "bar"; puts foo }

   harp:~ > ruby a.rb
   4
   bar
   2

by my reckoning that's only a few xtra chars

if one wanted to do that alot you can just

   harp:~ > cat a.rb
   class Array
     def merge *mask
       zip(mask.flatten).map{|v| v.first or v.last}
     end
     def merge! *mask
       replace merge(*mask)
     end
   end

   table =
     [
       [nil, 4, 2],
       [4, nil, 2],
       [4, 2, nil],
     ]

   table.each do |row|
     row.merge! defaults = %w(a b c)
     p row
   end

   harp:~ > ruby a.rb
   ["a", 4, 2]
   [4, "b", 2]
   [4, 2, "c"]


imho

   table.each do |row|; row.merge! %w(a b c)
     p row
   end

is very nearly as clear and as concise as

   table.each do |x = 'a', y = 'b', z = 'c'|
     row = [x, y, z]
     p row
   end

and this extends to multi-parm blocks just as easily

   assoc_array.each do |k = 'no key', v = 'no val'|
     p [k, v]
   end

   assoc_array.each do |kv|; kv.merge! 'no key', 'no val'
     p kv
   end

i guess i'm just thinking block parameters, and method parameters, are always
lists (possibly empty) and that a nifty new list operator could solve this
with even saying yac...

regards.

-a
-- 
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze.  --Nagarjuna
===============================================================================