[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-core
Subject:    [ruby-core:35373] Re: [Ruby 1.9 - Bug #4440] [Open] odd evaluation
From:       Yusuke ENDOH <mame () tsg ! ne ! jp>
Date:       2011-02-24 14:37:56
Message-ID: AANLkTi=Wq27EQAqrizZB5kNz8-9H2ihx9kCo8FbqFjE9 () mail ! gmail ! com
[Download RAW message or body]

Sorry, I've sent a Japanese mail to ruby-core by mistake.
Translation :-)

Hi,

I have believed that Ruby evaluates everything from left to
right, but was betrayed by a multiple assignment:

  def foo
    p :foo
    []
  end
  def bar
    p :bar
  end

  x, foo[0] = bar, 0

Because "foo" precedes "bar", I expect that this prints :foo
and :bar in this order, but actually :bar and :foo.


I think that this is a matter in practice.  For example,

  x, y = y, x

is used to swap the two, but

  obj, obj.foo = obj.foo, obj

does not so.  This kind of code is often written to rotate
a tree.  In fact I realized this behavior when I was writing
a splay tree, like this:

  t.left, t.left.right, t = t.left.right, t, t.left


I don't think that this should be fixed in 1.9 series, but
can we fix this in 2.0?


Some people (in Japanese IRC) said me that the behavior is
expected, but note that

  foo[0] = bar

does print :foo and :bar in the order.

-- 
Yusuke Endoh <mame@tsg.ne.jp>

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic