# Retry from proc-closure (LocalJumpError)

å’³ã¨ã„ã„ã¾ã™ã€‚

1.9ã®dRubyã®retryã®ãƒ†ã‚¹ãƒˆã§å›°ã£ã¦ã„ã¾ã™ã€‚

1.8ã§ç™ºç”Ÿã—ã¦ã„ãŸLocalJumpErrorãŒç™ºç”Ÿã—ãªããªã£ã¦ã—ã¾ã„ã€
dRubyã§retryã‚’æ•ã¾ãˆã‚‰ã‚Œãªããªã‚Šã¾ã—ãŸã€‚

% cat retry.rb
def test_retry
first = true
block = Proc.new do |x|
p x
if first
first = false
retry
end
end
[1].each do |x|
block.call(x)
end
end

test_retry

% ruby -v
ruby 1.8.6 (2007-11-13 patchlevel 5000) [powerpc-darwin9.0.0]

% ruby retry.rb
1
retry.rb:7:in `call': retry from proc-closure (LocalJumpError) from retry.rb:11:in`test_retry’
from retry.rb:10:in `each' from retry.rb:10:in`test_retry’
from retry.rb:15

1.9ã§ã¯æ¬¡ã®ã‚ˆã†ã«ãªã‚Šã¾ã™â€¥

% ruby19 -v
ruby 1.9.0 (2007-11-26 patchlevel 0) [powerpc-darwin9.1.0]
% ruby19 retry.rb
1
1

e\$B31\$H\$\$\$\$\$^\$9!#e(B

e\$B:{ED\$5\$s\$"\$j\$,\$H\$&\$4\$6\$\$\$^\$9!#e(B

On 2007/12/19, at 18:19, SASADA Koichi wrote:

e\$B!!\$^\$:!\$A0Ds\$H\$7\$F!\$e(BRuby 1.9 e\$B\$G\$O%V%m%C%/Cf\$K5-=R\$9\$ke(B
retry e\$B\$,\$J\$/\$Je(B
e\$B\$j\$^\$7\$?!%\$3\$l\$O!\$e(Bruby-core e\$B\$G9T\$o\$l\$?5DO@\$G!\$\$^\$D\$be(B
e\$B\$H\$5\$s\$,\$=\$&7h\$ae(B
e\$B\$^\$7\$?!%e(B

e\$BN,e(B

e\$B!!\$H\$\$\$&\$o\$1\$G!\$\$3\$NLdBj\$O2r7h\$H\$\$\$&\$3\$H\$GNI\$\$\$G\$7\$g\$&\$+!%e(B

e\$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\$k\$HBP1~\$9\$ke(B begin
e\$B\$+\$i;O\$^\$k5!G=\$Oe(B
e\$B;D\$j\$^\$9!%e(B

e\$B!!\$D\$^\$j!\$e(B

e\$B!!e(B1.times{ retry } e\$B\$Oe(B SyntaxError

e\$B!!e(Bbegin
raise
rescue
retry
end

e\$B\$O=>MhDL\$j\$H\$J\$j\$^\$9!%e(B

e\$B!!\$?\$@\$7!\$e(B

begin
raise
rescue
1.times{ retry }
end

e\$B\$O!\$=>Mh\$Oe(B 1.times e\$B\$r\$d\$j\$J\$*\$9;EAH\$\$G\$7\$?\$,!\$e(B1.9
e\$B\$N:#\$N>uBV\$G\$Oe(B
e\$B!Ve(BSyntaxErrore\$B\$K\$J\$j\$^\$9!W!%\$3\$NLdBj!J!)!K\$O!\$e(B1.9.2
e\$B0J9
\$Ge(B begin e\$B\$+\$ie(B
e\$B:F3+\$9\$k\$h\$&\$K\$J\$k\$+\$b\$7\$l\$^\$;\$s!%e(B

e\$B!!\$H\$\$\$&\$o\$1\$G!\$\$3\$NLdBj\$O2r7h\$H\$\$\$&\$3\$H\$GNI\$\$\$G\$7\$g\$&\$+!%e(B

e\$B!!\$A\$J\$\$K!\$:#F|\$N%3%%C%H\$Ge(B retry e\$B\$r:o\$C\$?\$N\$G\$9\$,!\$e(Bdrb
e\$B\$Ne(B lib,
sample
e\$B\$N\$[\$&\$GBP1~\$9\$k\$H;W\$o\$l\$k%3!<%I\$r:o\$i\$;\$F\$\$\$?\$@\$-\$^\$7\$?!J%3e(B
e\$B%s%Q%\$%k;~\$K%(%i!<\$K\$J\$k\$N\$G!\$;D\$C\$F\$\$\$k\$H%F%9%H\$,DL\$i\$J\$/\$J\$k!K!%\$9e(B
e\$B\$_\$^\$;\$s\$,!\$\$43NG’\$\$\$?\$@\$1\$J\$\$\$G\$7\$g\$&\$+!%e(B

# Index: lib/drb/invokemethod.rb

— lib/drb/invokemethod.rb (e\$B%j%S%8%g%se(B 14322)
+++ lib/drb/invokemethod.rb (e\$B:n6H%3%T!<e(B)
@@ -20,8 +20,6 @@ module DRb
end
if jump_error
case jump_error.reason

• ``````       when :retry
``````
• ``````         retry
when :break
break(jump_error.exit_value)
else
``````

# Index: test/drb/drbtest.rb

— test/drb/drbtest.rb (e\$B%j%S%8%g%se(B 14322)
+++ test/drb/drbtest.rb (e\$B:n6H%3%T!<e(B)
@@ -305,18 +305,19 @@ module DRbAry
assert_equal([1, 2, ‘III’, ‘III’, 4, ‘five’, 6], ary)
end

• def test_04_retry
• retried = false
• ary = []
• @there.each do |x|
• `````` ary.push x
``````
• `````` if x == 4 && !retried
``````
• retried = true
• retry
• `````` end
``````
• end
• assert_equal([1, 2, ‘III’, 4, 1, 2, ‘III’, 4, ‘five’, 6], ary)
• end
• # retry in block is not supported on ruby 1.9

• #def test_04_retry

• # assert_equal([1, 2, ‘III’, 4, 1, 2, ‘III’, 4, ‘five’, 6], ary)

• #end

def test_05_break
ary = []

# Index: sample/drb/darrayc.rb

## — sample/drb/darrayc.rb (e\$B%j%S%8%g%se(B 14322) +++ sample/drb/darrayc.rb (e\$B:n6H%3%T!<e(B) @@ -45,15 +45,3 @@ ro.each do |x| puts count redo if count == 3 end

-puts “# each, retry”
-retried = false
-ro.each do |x|

• puts x
• if x == 4 && !retried
• puts ‘retry’
• retried = true
• retry
• end
-end