From: "David A. Black" Date: 2007-10-02T22:25:26+09:00 Subject: Re: a = b = c order of evaluation weird --1926193751-378101879-1191331521=:14474 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-378101879-1191331521=:14474" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-378101879-1191331521=:14474 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Tue, 2 Oct 2007, Mariusz P=C4~Ykala wrote: > On 2007-10-02 21:06:32 +0900 (Tue, Oct), Calamitas wrote: >> My impression was that the OP knew what the evaluation order is, but >> not why it is like that. >> >> But anyway, my take on this is that >> >> a[0..a.size/2] =3D a[a.size*2/3..-1] =3D nil >> >> is equivalent to: >> >> a.[]=3D(0..a.size/2, a.[]=3D(a.size*2/3..-1, nil)) >> >> Arguments are evaluated left to right, completely explaining the >> evaluation order the OP is seeing. > > I guess it's safer to say that the order of evaluating arguments is > undefined, unless it is stated somewhere. > > Is it defined for ruby? I believe that a subscript expression is always going to be evaluated first: irb(main):001:0> a =3D [1,2,3,4,5] =3D> [1, 2, 3, 4, 5] irb(main):002:0> b =3D 1 =3D> 1 irb(main):003:0> a[b] =3D (b =3D 10) =3D> 10 irb(main):004:0> a =3D> [1, 10, 3, 4, 5] David --=20 Upcoming training from Ruby Power and Light, LLC: * Intro to Ruby on Rails, Edison, NJ, October 23-26 * Advancing with Rails, Edison, NJ, November 6-9 Both taught by David A. Black. See http://www.rubypal.com for more info! --1926193751-378101879-1191331521=:14474-- --1926193751-378101879-1191331521=:14474--