[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Compound Parallel Operators

Amos King

10/5/2006 8:23:00 PM

I think it looks like a good idea. It doesn't seem to be a huge leap,
but it may make code hard to read for some. I started out as a c
programmer and it shocked me the first time I ran into a,b,c=x,y,z. I
was completely confused.

On 10/5/06, Gavin Kistner <gavin.kistner@anark.com> wrote:
> (I didn't see an RCR for this, and my lazy 60s of searching didn't find
> any discussion about it. If it's been discussed before, just say so and
> I'll go hunt for the discussion properly.)
>
> Ruby allows parallel assignment:
> a,b,c = x,y,z
>
> Ruby interprets compound operators:
> a *= x
> as
> a = a * x
>
> Wouldn't it be nice if all compound operators worked with parallel
> assignment?
> a,b,c *= x,y,z
> would thus be interpreted as
> a *= x
> b *= y
> c *= z
>
> I think it'd be nice, anyhow. It simplifies a small subset of code, but
> it seems like a simple logical extension. (And, it's currently a syntax
> error, so there's no backwards compat issues, right?)
>
> a,b,c += *vals
> versus
> a,b,c = [a,b,c].zip( vals ).map{ |a,b| a+b }
> or
> a += vals[0]
> b += vals[1]
> c += vals[2]
>
>


--
Amos King
USPS
Programmer/Analyst
St. Louis, MO