From: Jean-Hugues ROBERT Date: 2004-04-29T04:30:29+09:00 Subject: Re: Array to Hash At 01:12 29/04/2004 +0900, you wrote: >On 0424, Florian Gross wrote: > > pair, (key, value) = ["one", 1], ["two", 2] > > pair # => ["one", 1] > > key # => "two" > > value # => 2 > >Why _cannot_ I simply say? >pair, [key, value] = ["one,1],["two",2] >[] is for arrays, () is for tuples. Why, yeah, Why ? In the context of a lvalue (something at the left of the assignment operator), you must provide a lvalue, instead of a value. It is easy to build values, included nested one using []. But only the compiler can build a lvalue. Probably for historical reasons, the compiler wants parenthesis within lvalue. And infer the missing outer ones when it encounter a , before =. I suppose that the reason is related to the syntax for formal argument description: def meth( a, b, c) end As a result def meth( a, [b1,b2], c) looks unbalanced compared to def meth( a, (b1,b2), c) that Ruby requires. I guess this is why the later syntax was picked, and propagated up to the = assignment operator. Note: That syntax applies for Proc's parameters too. I suppose that there is some true value in that syntax, because, within (), access to variables is by reference, not by value. All of this is the result of evolution. For sure, something like a, = meth() is not as obvious as (a) = meth() or, better, [a] = meth(). But that's the way it is, I suppose you have to accept it. Yours, Jean-Hugues >Gergo > >-- >+-[ Kontra, Gergely PhD student Room IB113 ]---------+ >| http://www.mcl.hu/~kgergely "Olyan langesz vagyok, hogy | >| Mobil:(+36 20) 356 9656 ICQ: 175564914 poroltoval kellene jarnom" | >+-- Magyar php mirror es magyar php dokumentacio: http://hu.php.net --+ ------------------------------------------------------------------------- Web: http://hdl.handle.net/1030.37/1.1 Phone: +33 (0) 4 92 27 74 17