[#38988] Re: [ruby-cvs:31575] Ruby:r24357 (trunk): * bootstraptest/runner.rb: made executable. — Yukihiro Matsumoto <matz@...>
まつもと ゆきひろです
[#38996] [Bug #1872] [ruby_1_8] Kernel#system doesn't work in forked process — Hidetoshi Nagai <redmine@...>
Bug #1872: [ruby_1_8] Kernel#system doesn't work in forked process
[#39006] [Bug #1787] URI ライブラリの正規表現パターン — Yui NARUSE <redmine@...>
チケット #1787 が更新されました。 (by Yui NARUSE)
[#39029] [bug:trunk] Re: [ruby-cvs:31633] Ruby:r24415 (trunk): * ext/digest/sha2/sha2.[ch]: Update to 1.0 RELEASE which fixes an — "U.Nakamura" <usa@...>
こんにちは、なかむら(う)です。
At Thu, 6 Aug 2009 14:07:19 +0900,
こんにちは、なかむら(う)です。
[#39035] [Bug #1904] cmp required? — Kazuhiro NISHIYAMA <redmine@...>
Bug #1904: cmp required?
[#39038] [Feature:1.9] How about IPAddr#<=> to take care of mask_addr? — Nobuhiro IMAI <nov@...>
いまいです。
いまいです。
いまいです。
[#39052] Fwd: [redmine4ruby-lang:253] [Bug #1914] ruby-1.9.1-p243 failed to build from source on aix 5.3 with gcc 4.2.0 — Yugui <yugui@...>
Redmine管理用プロジェクトに報告されてしまったので転送します。
金本と申します。
なかだです。
金本と申します。
[#39065] ChangeLog for r2004 (ruby-mode.el) — TAKAHASHI Kaoru <kaoru-ml@...>
高橋@TNTです。
[#39090] Re: [ruby-cvs:31774] Ruby:r24556 (trunk): * lib/date/format.rb: reverted. — "NARUSE, Yui" <naruse@...>
tadf@ruby-lang.org wrote:
> これですが、[ruby-dev:39089]との事なので修正お願いします。
Tadayoshi Funaba wrote:
[#39096] Re: [ruby-cvs:31781] Ruby:r24563 (trunk): * numeric.c (flo_pow,fix_pow): may return complex number. — Yukihiro Matsumoto <matz@...>
まつもと ゆきひろです
[#39106] [Feature #1951] openのBOM指定拡張 — Yui NARUSE <redmine@...>
Feature #1951: openのBOM指定拡張
[#39107] [Bug #1952] cannot stop with Ctrl+C — Usaku NAKAMURA <redmine@...>
Bug #1952: cannot stop with Ctrl+C
こんにちは、なかむら(う)です。
まつもと ゆきひろです
こんにちは、なかむら(う)です。
まつもと ゆきひろです
[#39109] StopIteration#result — Tanaka Akira <akr@...>
StopIteration#result を新設するのはどうでしょう?
In article <877hx1nmkp.fsf@fsij.org>,
まつもと ゆきひろです
In article <E1MdWX5-0000CL-4f@x61.netlab.jp>,
[#39146] [Bug #1967] Segmentation fault at test_qsort1 and test_qsort2 in test/dl/test_func.rb running on sparc-solaris-2.10 — Naohisa Goto <redmine@...>
Bug #1967: Segmentation fault at test_qsort1 and test_qsort2 in test/dl/test_func.rb running on sparc-solaris-2.10
[#39148] [Bug #1969] irb will be stuck with long variable name with completion.rb — Yoshimasa Niwa <redmine@...>
Bug #1969: irb will be stuck with long variable name with completion.rb
[#39150] [Bug #1976] Errors in test/fileutils/test_fileutils.rb — Kazuhiro NISHIYAMA <redmine@...>
Bug #1976: Errors in test/fileutils/test_fileutils.rb
[#39152] [Bug #1977] test failed in test_isdigit in test/dl/test_func.rb on sparc-solaris-2.10 (64bit) — Naohisa Goto <redmine@...>
Bug #1977: test failed in test_isdigit in test/dl/test_func.rb on sparc-solaris-2.10 (64bit)
チケット #1977 が更新されました。 (by Aaron Patterson)
[#39167] [Bug #2000] Change the license to "GPLv2+ or Ruby's original". — Mamoru Tasaka <redmine@...>
Bug #2000: Change the license to "GPLv2+ or Ruby's original".
[#39183] defining {file,line,name} methods for each backtrace entry — "Akinori MUSHA" <knu@...>
バックトレースの各行は整形済み文字列になっていますが、それを
[#39184] URI.escape_component — "Akinori MUSHA" <knu@...>
JavaScript の escapeURIComponent() 相当の関数ってありましたっけ?
[#39193] Re: [ruby-cvs:31917] Ruby:r24699 (trunk): * lib/tmpdir.rb (Dir.mktmpdir): removed thread race condition. — Tanaka Akira <akr@...>
In article <200908281827.n7SIRbaX003476@ci.ruby-lang.org>,
なかだです。
In article <4a988633.9553f10a.4496.483e@mx.google.com>,
なかだです。
In article <4a989f76.1602be0a.3de4.1131@mx.google.com>,
まつもと ゆきひろです
なかだです。
In article <4a9b9f29.1cba720a.7bf1.369b@mx.google.com>,
なかだです。
In article <4a9f873c.22035a0a.40fb.2740@mx.google.com>,
小崎と申します
In article <20090904093921.9132.A69D9226@jp.fujitsu.com>,
[#39203] [Feature #2017] String#/(sep) — Yui NARUSE <redmine@...>
Feature #2017: String#/(sep)
[ruby-dev:39109] StopIteration#result
StopIteration#result を新設するのはどうでしょう?
以下の例で、StopIteration#result は、(ブロックつきの)
Array#each の返り値を返します。
a = [1,2,3]
e = a.enum_for(:each)
p e.next #=> 1
p e.next #=> 2
p e.next #=> 3
e.next rescue p $!.result #=> [1, 2, 3]
Array#each はその配列自体を返すので、$!.result は [1, 2, 3]
になっています。
Enumerator で外部イテレータを作って使うと、内部イテレータを
Fiber 内で動かします。each などの内部イテレータは終了すると
きに何か値を返すわけですが、現在はその値を得る方法がありませ
ん。
まぁ、直接何かに役に立つかというと疑わしい気がしますが、外部
イテレータを使って内部イテレータを実装するときに後者の返り値
を前者から指定できるとか、ちょっとメタなことをやろうとしたと
きに使える気がします。
StopIteration#result は外部イテレータと内部イテレータの機能
のずれを除去する、ともいえます。完全性というか。
というわけでどうでしょうか。
% svn diff --diff-cmd diff -x '-u -p'
Index: enumerator.c
===================================================================
--- enumerator.c (revision 24578)
+++ enumerator.c (working copy)
@@ -33,7 +33,7 @@ struct enumerator {
VALUE fib;
VALUE dst;
VALUE lookahead;
- VALUE no_next;
+ VALUE stop_exc;
};
static VALUE rb_cGenerator, rb_cYielder;
@@ -284,7 +284,7 @@ enumerator_init(VALUE enum_obj, VALUE ob
ptr->fib = 0;
ptr->dst = Qnil;
ptr->lookahead = Qundef;
- ptr->no_next = Qfalse;
+ ptr->stop_exc = Qfalse;
return enum_obj;
}
@@ -506,14 +506,23 @@ next_ii(VALUE i, VALUE obj, int argc, VA
return Qnil;
}
+
+static VALUE
+stop_result(VALUE self)
+{
+ return rb_attr_get(self, rb_intern("result"));
+}
+
static VALUE
next_i(VALUE curr, VALUE obj)
{
struct enumerator *e = enumerator_ptr(obj);
VALUE nil = Qnil;
+ VALUE result;
- rb_block_call(obj, id_each, 0, 0, next_ii, obj);
- e->no_next = Qtrue;
+ result = rb_block_call(obj, id_each, 0, 0, next_ii, obj);
+ e->stop_exc = rb_exc_new2(rb_eStopIteration, "iteration reached at end");
+ rb_ivar_set(e->stop_exc, rb_intern("result"), result);
return rb_fiber_yield(1, &nil);
}
@@ -552,8 +561,8 @@ enumerator_next(VALUE obj)
return v;
}
- if (e->no_next)
- rb_raise(rb_eStopIteration, "iteration reached at end");
+ if (e->stop_exc)
+ rb_exc_raise(e->stop_exc);
curr = rb_fiber_current();
@@ -562,11 +571,11 @@ enumerator_next(VALUE obj)
}
v = rb_fiber_resume(e->fib, 1, &curr);
- if (e->no_next) {
+ if (e->stop_exc) {
e->fib = 0;
e->dst = Qnil;
e->lookahead = Qundef;
- rb_raise(rb_eStopIteration, "iteration reached at end");
+ rb_exc_raise(e->stop_exc);
}
return v;
}
@@ -617,7 +626,7 @@ enumerator_rewind(VALUE obj)
e->fib = 0;
e->dst = Qnil;
e->lookahead = Qundef;
- e->no_next = Qfalse;
+ e->stop_exc = Qfalse;
return obj;
}
@@ -915,6 +924,7 @@ Init_Enumerator(void)
rb_define_method(rb_cEnumerator, "inspect", enumerator_inspect, 0);
rb_eStopIteration = rb_define_class("StopIteration", rb_eIndexError);
+ rb_define_method(rb_eStopIteration, "result", stop_result, 0);
/* Generator */
rb_cGenerator = rb_define_class_under(rb_cEnumerator, "Generator", rb_cObject);
Index: test/ruby/test_enumerator.rb
===================================================================
--- test/ruby/test_enumerator.rb (revision 24578)
+++ test/ruby/test_enumerator.rb (working copy)
@@ -152,5 +152,14 @@ class TestEnumerator < Test::Unit::TestC
assert_raise(StopIteration) { e.next }
assert_raise(StopIteration) { e.next }
end
+
+ def test_stop_result
+ a = [1]
+ res = a.each {}
+ e = a.each
+ assert_equal(1, e.next)
+ exc = assert_raise(StopIteration) { e.next }
+ assert_equal(res, exc.result)
+ end
end
--
[田中 哲][たなか あきら][Tanaka Akira]