ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
From: Yusuke Endoh <mame@tsg•ne.jp>
To: ruby-dev@ruby-lang.org (ruby developers list)
Subject: [ruby-dev:43727] [Ruby 1.9 - Bug #4443] odd evaluation order in a multiple assignment
Date: Sat, 11 Jun 2011 16:04:37 +0900	[thread overview]
Message-ID: <redmine.journal-17752.20110611160434@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-4443.20110224232852@ruby-lang.org


Issue #4443 has been updated by Yusuke Endoh.


http://redmine.ruby-lang.org/issues/4440
に matz の返事があります。

> 優先順位は高くありませんが、直すべきだと思います。
>
> とはいうものの、1.8のころからこうだったのですし、直すのが難しいのも確
> かなのですが。

確か redmine の更新直後で、インターフェイスの違いにハマってチケット登録に失敗してしまったのでした。

-- 
Yusuke Endoh <mame@tsg•ne.jp>
----------------------------------------
Bug #4443: odd evaluation order in a multiple assignment
http://redmine.ruby-lang.org/issues/4443

Author: Yusuke Endoh
Status: Assigned
Priority: Normal
Assignee: Yukihiro Matsumoto
Category: 
Target version: 2.0
ruby -v: ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]


=begin
遠藤です。core に投げてしまったようなので登録し直し。

Ruby は左から右に評価が進むと信じていたのですが、多重代入で裏切られました。

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

  x, foo[0] = bar, 0

bar より foo が左にあるので、:foo 、:bar の順に出力されることを期待するのですが、なんと :bar 、:foo になります。

具体的に何が困るかというと、例えば

  obj, obj.foo = obj.foo, obj

には swap を期待するわけですが、そうなりません。こういうコードは実際に、木の回転などを実装するときにしばしば書きたくなります。この挙動に気がついたのも splay tree を実装していたときでした。こんなの:

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

1.9 系列で修正すべきとまでは思いませんが、2.0 で直る可能性はあるでしょうか。

IRC で話したら「それで普通」みたいな反応もありましたが、

  foo[0] = bar

はちゃんと :foo 、:bar の順に出ます。

-- 
Yusuke Endoh <mame@tsg•ne.jp>
=end



-- 
http://redmine.ruby-lang.org

  parent reply	other threads:[~2011-06-11  7:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-24 14:25 [ruby-dev:43272] [Ruby 1.9 - Bug #4443] [Open] odd evaluation order in a multiple assignment Yusuke Endoh
2011-06-11  6:49 ` [ruby-dev:43724] [Ruby 1.9 - Bug #4443] " Koichi Sasada
2011-06-11 13:28   ` [ruby-dev:43747] " Yukihiro Matsumoto
2011-06-11  7:04 ` Yusuke Endoh [this message]
2012-04-10  9:35 ` [ruby-dev:45502] [ruby-trunk " matz (Yukihiro Matsumoto)
2012-04-10 11:57 ` [ruby-dev:45503] " mame (Yusuke Endoh)
2012-04-27  5:28 ` [ruby-dev:45586] " matz (Yukihiro Matsumoto)
2012-07-14  5:51 ` [ruby-dev:45952] " ko1 (Koichi Sasada)
2012-10-25 20:33 ` [ruby-dev:46272] [ruby-trunk - Bug #4443][Open] " nahi (Hiroshi Nakamura)
2012-10-30  0:09 ` [ruby-dev:46315] [ruby-trunk - Bug #4443] " ko1 (Koichi Sasada)
2015-08-21 21:09 ` [ruby-dev:49232] [Ruby trunk " ko1
2017-01-31  9:01 ` [ruby-dev:49970] [Ruby trunk Bug#4443] " ko1
2018-01-24  8:36 ` [ruby-dev:50426] " akr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-17752.20110611160434@ruby-lang.org \
    --to=ruby-dev@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).