Fiber reviesed

[email protected]$G$9!%e(B

e$B!!$$$m$$$m$He(B Fiber
e$B$N;EMM$rG:$s$G$$$?$s$G$9$,!$7h$a$^$7$?!%$G!$<BAue(B
e$B$7$F%3%_%C%H$7$^$7$?!%e(B

e$B!&e(BFiber e$B$O%;%_%3%k!<%A%se(B

e$B!!e(BLua e$B$de(B Python
e$B$G$*$J$8$$N%;%%3%k!<%A%s$G$9!%DL>o$O$3$A$i$G==J,[email protected](B
e$B$H;W$$$^$9!%e(B

e$B!!e(BFiber#resume e$B$GBP>]%U%!%$%P$X%9%$%C%A!$e(BFiber.yield
e$B$Ge(B resume e$B$7$?e(B
e$B%U%!%$%P$XLa$j$^$9!%e(BLua
e$B$N%$%s%?!<%U%’!<%9$=$N$^$^$G$9!%e(BPython e$B$Ne(B
e$B%8%’%M%l!<%[email protected]$&$H!$e(Bnext e$B$He(B yield e$B$K$"$?$j$^$9!%e(B

e$B!!Nc30$,H/@8$9$k$H!$e(Bresume e$B$7$??M$KNc30$,EAGE$7$^$9!%e(B

e$B!!%U%!%$%P$,=*N;$9$k$H!$$=$N%V%m%C%/$NJV$jCM$re(B resume
e$B$7$?%U%!%$%P$Xe(B
e$BJV$7$^$9!%e(B

e$B!!$R$H$D$N%U%!%$%P$rB?=E$Ke(B resume
e$B$9$k$3$H$O$G$-$^$;$s!%%(%i!<$K$J$je(B
e$B$^$9!%e(B
->
e$B$3$l$GLdBj$K$J$k$3$H$C$F$"$j$^$9$+$M!)!!e(BPythone$B$N%8%’%M%l!<%?$be(B
e$B$=$&$+$H;W$C$?$N$G$9$,!$Nc$K$h$C$F$O$:$7$F$k$+$b!%e(B

fib = Fiber.new{
Fiber.yield 10
20
}

p fib.resume #=> 10
p fib.resume #=> 20
p fib.resume #=> FiberError

e$B!&e(BFiber::Core e$B$O%3%k!<%A%se(B

e$B!!e(BFiber::Core#transfer
e$B$H$$$&%a%=%C%I$G!$%U%!%$%P4V$r0\F0$7$^$9!%8<e(B
e$B?M8~$1!%e(B

e$B!!Nc30$,H/@8$7$?$ie(B root fiber e$B$XEAGE$7$^$9!%=*N;$b!$e(Broot
fiber e$B$XLae(B
e$B$j$^$9!%[email protected])8f$,Fq$7$$$$$N$G8<?M8~$1!%e(B

e$B!!$A$J$_$K!$e(Broot fiber e$B$Oe(B Fiber::Core
e$B$N%$%s%?!<%U%’!<%9$K$J$j$^$9e(B
e$B!Je(Bresume e$B=PMh$J$$$7!K!%e(B

e$B!!e(BFiber::Core
e$B$H$$$&$N$O!$L>A0$,NI$/$J$$$H;W$&!%$1$I!$$[$+$K;W$$Ib$+e(B
e$B$P$J$+$C$?!%e(B

e$B!!$I$s$J$b$s$G$7$g$&$+!%e(B

e$BA0ED$G$9!#e(B

On 08/22/2007 04:03 AM, SASADA Koichi wrote:

e$B!!e(BFiber::Core e$B$H$$$&$N$O!$L>A0$,NI$/$J$$$H;W$&!%$1$I!$$[$+$K;W$$Ib$+e(B
e$B$P$J$+$C$?!%e(B

e$B$H$$$&$+!"%;%_%3%k!<%A%s$Ke(BFibere$B$H$$$&L>A0$rIU$1$k$N$,$h$/$Je(B
e$B$$$h$&$J5$$,$9$k$s$G$9$,!"$I$&$G$7$g$&$+!#e(B

[email protected]$G$9!%e(B

Shugo M. wrote:

e$B$H$$$&$+!"%;%_%3%k!<%A%s$Ke(BFibere$B$H$$$&L>A0$rIU$1$k$N$,$h$/$Je(B
e$B$$$h$&$J5$$,$9$k$s$G$9$,!"$I$&$G$7$g$&$+!#e(B

e$B!!$=$s$J5$$b$7$F$$$^$9!%$,!$e(BLua e$B$be(B coroutine
[email protected]$C$F$k$7!$$H$+!%e(B

e$B!!$J$s$+$$$$L>A0$,$"$l$P!$$<$RJQ$($?$$$N$G$9$,2?$,$$$$$G$7$g$&$+!%e(B

In article [email protected],
SASADA Koichi [email protected] writes:

e$B!!$=$s$J5$$b$7$F$$$^$9!%$,!$e(BLua e$B$be(B coroutine [email protected]$C$F$k$7!$$H$+!%e(B

e$B!!$J$s$+$$$$L>A0$,$"$l$P!$$<$RJQ$($?$$$N$G$9$,2?$,$$$$$G$7$g$&$+!%e(B

Coroutine e$B$G$$$$$s$8$c$J$$$G$9$+!#e(B

e$B1sF#$G$9!#e(B

e$B$$$m$$$m$He(B Fiber e$B$N;EMM$rG:$s$G$$$?$s$G$9$,!$7h$a$^$7$?!%$G!$<BAue(B
e$B$7$F%3%_%C%H$7$^$7$?!%e(B

e$B$*Hh$lMM$G$9!#LLGr$$$b$N$r$"$j$,$H$&$4$6$$$^$9!#e(B
e$B$5$C$=$/M7$s$G$$?$N$G$9$,!";DG0$J$,$i%3%k!<%A%s$H%;%%3%k!<%A%s$Oe(B
[email protected]$,0-$$$3$H$K5$$,$D$$$F$7$^$$$^$7$?!#e(B

Fiber e$B$NCf$Ge(B Fiber::Core
e$B$r=*$o$i$;$k$H!"$=$N;[email protected]$G<[email protected]$C$?e(B
Fiber e$B$,[email protected]$-$J$,$i1J1s$K<B9T$5$l$J$$!)!W>uBV$K$J$j$^$9!#e(B

f = Fiber.new do
Fiber::Core.new { }.transfer
p 1 # e$B$3$3$O1J1s$K<B9T$5$l$J$$!)e(B
end
f.resume
f.transfer
f.resume #=> double resume (FiberError)

e$BMW$9$k$K!"!Ve(BFiber
e$B$r%M%9%H$7$?$iJQ$J$3$H$K$J$k!W$H$$$&LdBj$,!Ve(BFiber e$B$Ne(B
e$BCf$Ge(B Fiber::Core
e$B$r;H$&$HJQ$J$3$H$K$J$k!W$KJQ$o$C$?$h$&$G$9!#e(B

e$BNc$($Pe(B Generator e$B$NCf$Ge(B Fiber::Core e$B$Ke(B transfer
e$B$9$k$H!"e(BGenerator e$B$+$ie(B
next e$B$r<h$m$&$H$9$k$7$?$H$-JQ$J$3$H$K$J$j$^$9!#e(B

def (o = Object.new).foo
yield 1
yield 2
yield 3
Fiber::Core.new { }.transfer
end

g = o.to_enum(:foo)
p g.next #=> 1
p g.next #=> 2
p g.next #=> nil (?)
p g.next #=> double resume (FiberError) (??)

e$B2r7h$NJ}?K$r$$$/$D$+9M$($F$_$^$7$?!#e(B

  • Fiber::Core e$B$r$J$/$9e(B
  • Fiber::Core e$B$N=*N;;[email protected]$re(B root fiber e$B0J30$K$9$ke(B
    (e$B$8$c$"$I$3!)e(B)
  • Fiber::Core e$B$r8F$S=P$;$k$N$Oe(B root fiber [email protected]$1!"$K$9$ke(B
    (e$BITJX$=$&e(B)
  • Fiber::Core e$B$Oe(B callcc
    e$BJB$N9uKb=Q$G$"$k!"$H%l%C%F%k$rE=$C$F;H$o$;$J$$e(B

e$BL>>N$K$D$$$F$O!";d$Oe(B Fiber e$B$N$^$^$G$b$$$$$H;W$$$^$9!#e(B
Fiber e$B$de(B Coroutine
e$B$H$$$&[email protected]$K$O!"$A$c$s$H$7$?Dj5A$b%3%s%;%s%5%9$be(B
e$B$J$$$h$&$J$N$G!"[email protected]$C$?$b$s>!$A$G$9!#e(B
Lua [email protected]$C$F<+J,$?$A$Ge(B “Semi”-coroutine e$B$HG’$a$F$$$k$b$N$He(B
Coroutine e$B$He(B
e$B8F$s$G$k$o$1$G$9$7!#e(B
[email protected]$+$iC;$/$F$+$C$3$$$$$N$rA*$Y$P$$$$$H;W$$$^$9!#e(B

e$B$*$^$1!#0J2<$GMn$A$^$7$?!#7QB3$,8F$S=P$;$F$k;[email protected]$G2?$+4V0c$$!)e(B

i = 0
callcc {|c| $c = c }
raise if i == 2
i += 1
Fiber::Core.new { $c.call }.transfer

[email protected]$G$9!%e(B

Yusuke ENDOH wrote:

  • Fiber::Core e$B$Oe(B callcc e$BJB$N9uKb=Q$G$"$k!"$H%l%C%F%k$rE=$C$F;H$o$;$J$$e(B

e$B!!$3$l$r9M$($F$$$^$7$?!%e(BFiber::Core#transfer
e$B$O!$$$$m$s$JA0Ds$r$V$Ae(B
e$B2u$7$^$9$+$i!%$J$N$G!$M}@-E*$K9M$($l$P:o$kBP>]$J$s$G$9$,!$2?$+MxMQMQe(B
e$BES$,$"$k$+$b$7$l$J$$$H$$$&%@%a$J4|BT$G;D$7$F$$$^$9!%e(B

e$B!!$=$b$=$b!$e(BFiber e$B$be(B Enumerator e$B$Ge(B generator
e$B$r:n$l$k$h$&$K$7$F$*$1e(B
e$B$P!$$b$&MW$i$J$$$H;W$C$F$$$^$9!%e(B

e$B!!e(BFiber::DangerousCore#transfer
e$B$H$+$N1#$75!G=$K$7$F$7$^$*$&$+!%e(B
e$B$"!$3HD%%i%$%V%i%j$K$7$F!$$I$&$7$F$bI,[email protected]$1;H$&!$$,$$$$$N$+$b$7e(B
e$B$l$^$;$s!%e(B

e$B!!$"$H!$e(BFiber.current e$B$OITMW$J$N$G:o$kM=Dj$G$9!%e(B

e$BL>>N$K$D$$$F$O!";d$Oe(B Fiber e$B$N$^$^$G$b$$$$$H;W$$$^$9!#e(B
Fiber e$B$de(B Coroutine e$B$H$$$&[email protected]$K$O!"$A$c$s$H$7$?Dj5A$b%3%s%;%s%5%9$be(B
e$B$J$$$h$&$J$N$G!"[email protected]$C$?$b$s>!$A$G$9!#e(B
Lua [email protected]$C$F<+J,$?$A$Ge(B “Semi”-coroutine e$B$HG’$a$F$$$k$b$N$He(B Coroutine e$B$He(B
e$B8F$s$G$k$o$1$G$9$7!#e(B
[email protected]$+$iC;$/$F$+$C$3$$$$$N$rA*$Y$P$$$$$H;W$$$^$9!#e(B

e$B!!$$!$e(BFiber e$B$K0lI<$,!%e(B

e$B$*$^$1!#0J2<$GMn$A$^$7$?!#7QB3$,8F$S=P$;$F$k;[email protected]$G2?$+4V0c$$!)e(B

i = 0
callcc {|c| $c = c }
raise if i == 2
i += 1
Fiber::Core.new { $c.call }.transfer

e$B!!$&$&$s!$$=$&$+$b!%e(B

e$B1sF#$G$9!#e(B

  • Fiber::Core e$B$Oe(B callcc e$BJB$N9uKb=Q$G$"$k!"$H%l%C%F%k$rE=$C$F;H$o$;$J$$e(B

e$B!!$3$l$r9M$($F$$$^$7$?!%e(BFiber::Core#transfer e$B$O!$$$$m$s$JA0Ds$r$V$Ae(B
e$B2u$7$^$9$+$i!%$J$N$G!$M}@-E*$K9M$($l$P:o$kBP>]$J$s$G$9$,!$2?$+MxMQMQe(B
e$BES$,$"$k$+$b$7$l$J$$$H$$$&%@%a$J4|BT$G;D$7$F$$$^$9!%e(B

e$BN;2r$G$9!#e(B

e$B$=$b$=$b!$e(BFiber e$B$be(B Enumerator e$B$Ge(B generator e$B$r:n$l$k$h$&$K$7$F$*$1e(B
e$B$P!$$b$&MW$i$J$$$H;W$C$F$$$^$9!%e(B

e$B3N$+$K!#e(BFiber e$B$C$]$$$3$H$7$?$$$H$-$Oe(B Generator
e$B;H$($C$F$3$H$G$9$h$M!#e(B
e$B$=$N$?$a$K$O!">!<[email protected]$_$7$J$$$h$&$K$7$F$b$i$($k$H$&$l$7$$$G$9!#e(B

e$B;29Me(B: http://d.hatena.ne.jp/xtalco/20070818#1187434017

[email protected]$G$9!%e(B

Yusuke ENDOH wrote:

e$B$=$b$=$b!$e(BFiber e$B$be(B Enumerator e$B$Ge(B generator e$B$r:n$l$k$h$&$K$7$F$*$1e(B
e$B$P!$$b$&MW$i$J$$$H;W$C$F$$$^$9!%e(B

e$B3N$+$K!#e(BFiber e$B$C$]$$$3$H$7$?$$$H$-$Oe(B Generator e$B;H$($C$F$3$H$G$9$h$M!#e(B
e$B$=$N$?$a$K$O!">!<[email protected]$_$7$J$$$h$&$K$7$F$b$i$($k$H$&$l$7$$$G$9!#e(B

e$B;29Me(B: http://d.hatena.ne.jp/xtalco/20070818#1187434017

e$B!!$3$C$A$O$^$D$b$H$5$sBT$A$G$9$+$M$’!%e(B

e$B1sF#$G$9!#e(B

e$B$A$g$C$HD{@5$G$9!#e(B

Fiber e$B$NCf$Ge(B Fiber::Core e$B$r=*$o$i$;$k$H!"$=$N;[email protected]$G<[email protected]$C$?e(B
Fiber e$B$,[email protected]$-$J$,$i1J1s$K<B9T$5$l$J$$!)!W>uBV$K$J$j$^$9!#e(B

f = Fiber.new do
Fiber::Core.new { }.transfer
p 1 # e$B$3$3$O1J1s$K<B9T$5$l$J$$!)e(B
end
f.resume
f.transfer
f.resume #=> double resume (FiberError)

e$B2<$+$iFs9TL$Ne(B f.transfer e$B$r>C$7$F$/[email protected]$5$$!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:31611] Re: Fiber reviesed”
on Thu, 23 Aug 2007 04:04:43 +0900, SASADA Koichi [email protected]
writes:

|> e$B3N$+$K!#e(BFiber e$B$C$]$$$3$H$7$?$$$H$-$Oe(B Generator e$B;H$($C$F$3$H$G$9$h$M!#e(B
|> e$B$=$N$?$a$K$O!">!<[email protected]$_$7$J$$$h$&$K$7$F$b$i$($k$H$&$l$7$$$G$9!#e(B
|>
|> e$B;29Me(B: http://d.hatena.ne.jp/xtalco/20070818#1187434017
|
|e$B!!$3$C$A$O$^$D$b$H$5$sBT$A$G$9$+$M$’!%e(B

Xtale$B$Ne([email protected]$&0UL#$G$9$+!#$&!<$s!"$"$^$j;He(B
e$B$$$d$9$=$&$K;W$($J$$$N$G$9$,!#%9%T!<%I68$8$c$J$$$s$G!"%a%=%Ce(B
e$B%I8F$S=P$7e(B2e$B2s$H$+$KDq93$O$"$j$^$;$s$+$i!#e(B

e$BB>[email protected]$_$r$7$J$$<BAu$K$D$$$FDs0F$,$"$l$P<*$r79$1$^$9$1$I!#e(B

e$B1sF#$G$9!#e(B

|> e$B3N$+$K!#e(BFiber e$B$C$]$$$3$H$7$?$$$H$-$Oe(B Generator e$B;H$($C$F$3$H$G$9$h$M!#e(B
|> e$B$=$N$?$a$K$O!">!<[email protected]$_$7$J$$$h$&$K$7$F$b$i$($k$H$&$l$7$$$G$9!#e(B
|>
|> e$B;29Me(B: http://d.hatena.ne.jp/xtalco/20070818#1187434017
|
|e$B!!$3$C$A$O$^$D$b$H$5$sBT$A$G$9$+$M$’!%e(B

Xtale$B$Ne([email protected]$&0UL#$G$9$+!#$&!<$s!"$"$^$j;He(B
e$B$$$d$9$=$&$K;W$($J$$$N$G$9$,!#%9%T!<%I68$8$c$J$$$s$G!"%a%=%Ce(B
e$B%I8F$S=P$7e(B2e$B2s$H$+$KDq93$O$"$j$^$;$s$+$i!#e(B

next_iter e$B$N$h$&$KB?CM$rJV$9$N$O;d$b$"$^$jNI$/$J$$$H;W$$$^$9!#e(B
Xtal e$B$N>l9g$O!“DL>o$N%V%m%C%/8F$S=P$7$,e(B next_iter
e$B$J$I$N8F$S=P$7$Ne(B
e$B%7%s%?%C%/%9%7%e%,!<07$$$i$7$$$N$G!”%9%T!<%I$rL5;[email protected]$H;W$$$^$9!#e(B

Ruby e$B$N>l9g$Oe(B C# e$B$Ne(B IEnumerator e$B$G<BAu$5$l$F$$$k$H$$$&e(B
MoveNext e$B$He(B
Current e$B$N%$%s%?!<%U%’%$%9e(B ([email protected][email protected]$o$l$F$$$k$b$Ne(B)
e$B$,NI$$$H;W$$$^$9!#e(B
e$B%a%=%C%IL>$OD9$9$.$k$N$G!"$=$l$>$le(B next e$B$He(B value
e$B$J$s$F$I$&$G$7$g$&$+!#e(B

  • next :
    e$B<!$NMWAG$^$G?J$_!"?J$a$?$i??$rJV$9!"$5$b$J$/$P56$rJV$9!#e(B
  • value : e$B8=:_$NMWAG$rJV$9e(B

e$BIaDL$K%$%F%l!<%H$9$k%3!<%I$r9M$($k$H!"8=>u$N%$%s%?!<%U%’%$%9$G$Oe(B

g = obj.to_enum
while g.next?
v = g.next
…(v e$B$r;H$&e(B)…
end

e$B$H$J$k$N$,!"e(BIEnumerator e$BIw$N%$%s%?!<%U%’%$%[email protected]$He(B

g = obj.to_enum
while g.next
…(g.value e$B$r;H$&e(B)…
end

e$B$K$J$j$^$9!#I{:nMQ$NH/@8$9$k0LCV$,e(B while gets
e$B$HF1$846$8$K$J$j$^$9!#e(B
e$B;d$N463P$G$O8e<T$NJ}$,$h$j%7%s%W%k$G$9!#e(B

e$B0l2s$be(B g.next e$B$7$J$$$&$A$Ke(B g.value
e$B$7$?>l9g$,Ff$G$9$,!"Nc30$+$J!#e(B

e$B1sF#$G$9!#e(B

|next_iter e$B$N$h$&$KB?CM$rJV$9$N$O;d$b$"$^$jNI$/$J$$$H;W$$$^$9!#e(B
|Xtal e$B$N>l9g$O!“DL>o$N%V%m%C%/8F$S=P$7$,e(B next_iter e$B$J$I$N8F$S=P$7$Ne(B
|e$B%7%s%?%C%/%9%7%e%,!<07$$$i$7$$$N$G!”%9%T!<%I$rL5;[email protected]$H;W$$$^$9!#e(B

e$B$^$"!";T66$5$s$O%9%T!<%I68$_$?$$$G$9$+$i$M$(!#e(BPythone$B$OF1MM$Ne(B
e$B;E3]$1$GNc30$r;H$C$F$^$9!#e(B

e$B$J$k$[$I!#e(B

| - next : e$B<!$NMWAG$^$G?J$!"?J$a$?$i??$rJV$9!"$5$b$J$/$P56$rJV$9!#e(B
| - value : e$B8=:
$NMWAG$rJV$9e(B

nexte$B$He(Bvaluee$B$NN>J}$N%a%=%C%I$r;H$o$J$/$A$c$$$1$J$$$H$$$&[email protected]$,e(B
e$B%$%1$F$J$$5$$,$7$^$9!#<!!9$HMWAG$r<h$j=P$7$F4|[email protected]$1$J$N$Ke(B
e$B$$$A$$$A;vA0$K!V$^[email protected]$a$^$9$+!W$HJ9$+$J$/$A$c$$$1$J$$$N$,5$e(B
e$B$KF~$i$J$$!#e(B

e$B$=$l$Oe(B next? [email protected]$H;W$$$^$9!#e(B

e$B$8$c$"!"$I$&$9$k$+$H$$$&$He(BPythone$BJ}<0$,NI$$$s$8$c$J$$$+$H;W$$e(B
e$B$^$9!#$D$^$j!“e([email protected]$18F$s$G!“KvHx$KMh$?$ie(BStopIteratione$BNc30$,e(B
e$B5/$-$k$N$G!”$=$l$rJaB*$9$k$H$$$&!#Nc30%3%9%H$,5$$K$J$j$=$&$Ge(B
e$B$9$,!“[email protected]@h@8$K3NG’$7$?$H$3$m!”$[$H$s$ILdBj$Je(B
[email protected]$m$&$H$N$3$H$G$7$?e(B(e$B$^$”!"8=>ue(B(next?)e$B$h$j$A$g$C$H=E$$$N$G!"e(B
e$B%9%T!<%I68E*$K$O%$%d$=$&$G$7$?$1$Ie(B)e$B!#e(B

e$B$$!#$=$NJ}K!$GLdBj$,$J$$$J$i$=$l$,0lHVe:No$G$9$M!#e(B
e$B8zN($O$I$&$G$b$$$$$N$G$9$,!"$"$($F%$%s%M%s$r$D$1$k$J$i!D!De(B

  1. e$BNc30JaB*$N$?$a$K%$%s%G%s%H$,A}$($k$N$,%$%de(B
  2. e$BB>$NNc30$rJaB*$9$k$D$b$j$G=q$$$?e(B rescue
    e$B$K0z$C$+$+$C$F%P%0$N$b$He(B
  3. e$BNc30E*$G$J$$;v>]$rI=8=$9$k$N$KNc30$r;H$&$N$,>/$78e$m$a$?$$e(B
  4. e$B8D?ME*$Ke(B rescue
    e$B$N9=J8$N8+$?L$,9%$-$/$J$$$N$G=q$-$?$/$J$$e(B

e$B$5$i$KA0EDe(B(e$B=$8ce(B)e$B$/$s$N;W$$$D$-$K$h$k!Ve(Bloope$B$,e(BStopIteratione$BNce(B
e$B30$rJaB*$9$k!W$H$$$&%"%$%G%#%"$r$?$9$H!"$^$k$G2{$+$7$Ne(BSather
e$B$N$h$&$Ke(B

e = [1,2,3,4,5].each
loop do
p e.next
end

e$B$N$h$&$J$3$H$,$G$-$k$h$&$K$J$j$^$9!#AGE(!#e(B

Sather e$B$OCN$j$^$;$s$7<B:][email protected]$O$I$&$+$o$+$j$^$;$s$,!">e$NNc$Oe(B
e$B$+$C$3$$$$$G$9$M!#e(Brescue e$B$7$J$/$F$$$$$7!#e(B
break e$B$O<B$O!VJ8K!E*[email protected])8B$N$"$ke(B raise
StopIteratione$B!W$J$N$G$O$J$$$+!"e(B
e$B$J$I$H46$8$F$7$^$$$^$7$?!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:31636] Re: Fiber reviesed”
on Fri, 24 Aug 2007 19:39:13 +0900, “Yusuke ENDOH” [email protected]
writes:

|> | - next : e$B<!$NMWAG$^$G?J$!"?J$a$?$i??$rJV$9!"$5$b$J$/$P56$rJV$9!#e(B
|> | - value : e$B8=:
$NMWAG$rJV$9e(B
|>
|> nexte$B$He(Bvaluee$B$NN>J}$N%a%=%C%I$r;H$o$J$/$A$c$$$1$J$$$H$$$&[email protected]$,e(B
|> e$B%$%1$F$J$$5$$,$7$^$9!#<!!9$HMWAG$r<h$j=P$7$F4|[email protected]$1$J$N$Ke(B
|> e$B$$$A$$$A;vA0$K!V$^[email protected]$a$^$9$+!W$HJ9$+$J$/$A$c$$$1$J$$$N$,5$e(B
|> e$B$KF~$i$J$$!#e(B
|
|e$B$=$l$Oe(B next? [email protected]$H;W$$$^$9!#e(B

e$B$$$d!":#$G$be(Bnext + StopIteratione$BNc30$O;H$($^$9$+$i!#$C$F$$$&e(B
e$B$+!"e(BEnumerable#zipe$B$O$=$C$A$r;H$C$F$k$7!#e(B

|e$B$$!#$=$NJ}K!$GLdBj$,$J$$$J$i$=$l$,0lHVe:No$G$9$M!#e(B
|e$B8zN($O$I$&$G$b$$$$$N$G$9$,!"$"$($F%$%s%M%s$r$D$1$k$J$i!D!De(B
|
|1. e$BNc30JaB*$N$?$a$K%$%s%G%s%H$,A}$($k$N$,%$%de(B
|2. e$BB>$NNc30$rJaB*$9$k$D$b$j$G=q$$$?e(B rescue e$B$K0z$C$+$+$C$F%P%0$N$b$He(B
|3. e$BNc30E*$G$J$$;v>]$rI=8=$9$k$N$KNc30$r;H$&$N$,>/$78e$m$a$?$$e(B
|4. e$B8D?ME*$Ke(B rescue e$B$N9=J8$N8+$?L$,9%$-$/$J$$$N$G=q$-$?$/$J$$e(B

e$B$^$"!"$=$l$OJ,$+$j$^$9!#e(Bloope$B$H$NAH$_9g$o$;[email protected]$/e(B
e$B$H$$$&$3$H$G!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:31620] Re: Fiber reviesed”
on Thu, 23 Aug 2007 12:50:43 +0900, “Yusuke ENDOH” [email protected]
writes:

|next_iter e$B$N$h$&$KB?CM$rJV$9$N$O;d$b$"$^$jNI$/$J$$$H;W$$$^$9!#e(B
|Xtal e$B$N>l9g$O!“DL>o$N%V%m%C%/8F$S=P$7$,e(B next_iter e$B$J$I$N8F$S=P$7$Ne(B
|e$B%7%s%?%C%/%9%7%e%,!<07$$$i$7$$$N$G!”%9%T!<%I$rL5;[email protected]$H;W$$$^$9!#e(B

e$B$^$"!";T66$5$s$O%9%T!<%I68$_$?$$$G$9$+$i$M$(!#e(BPythone$B$OF1MM$Ne(B
e$B;E3]$1$GNc30$r;H$C$F$^$9!#e(B

|Ruby e$B$N>l9g$Oe(B C# e$B$Ne(B IEnumerator e$B$G<BAu$5$l$F$$$k$H$$$&e(B MoveNext e$B$He(B
|Current e$B$N%$%s%?!<%U%’%$%9e(B ([email protected][email protected]$o$l$F$$$k$b$Ne(B) e$B$,NI$$$H;W$$$^$9!#e(B
|e$B%a%=%C%IL>$OD9$9$.$k$N$G!"$=$l$>$le(B next e$B$He(B value e$B$J$s$F$I$&$G$7$g$&$+!#e(B
|
| - next : e$B<!$NMWAG$^$G?J$!"?J$a$?$i??$rJV$9!"$5$b$J$/$P56$rJV$9!#e(B
| - value : e$B8=:
$NMWAG$rJV$9e(B

nexte$B$He(Bvaluee$B$NN>J}$N%a%=%C%I$r;H$o$J$/$A$c$$$1$J$$$H$$$&[email protected]$,e(B
e$B%$%1$F$J$$5$$,$7$^$9!#<!!9$HMWAG$r<h$j=P$7$F4|[email protected]$1$J$N$Ke(B
e$B$$$A$$$A;vA0$K!V$^[email protected]$a$^$9$+!W$HJ9$+$J$/$A$c$$$1$J$$$N$,5$e(B
e$B$KF~$i$J$$!#e(B

e$B$8$c$"!"$I$&$9$k$+$H$$$&$He(BPythone$BJ}<0$,NI$$$s$8$c$J$$$+$H;W$$e(B
e$B$^$9!#$D$^$j!“e([email protected]$18F$s$G!“KvHx$KMh$?$ie(BStopIteratione$BNc30$,e(B
e$B5/$-$k$N$G!”$=$l$rJaB*$9$k$H$$$&!#Nc30%3%9%H$,5$$K$J$j$=$&$Ge(B
e$B$9$,!“[email protected]@h@8$K3NG’$7$?$H$3$m!”$[$H$s$ILdBj$Je(B
[email protected]$m$&$H$N$3$H$G$7$?e(B(e$B$^$”!"8=>ue(B(next?)e$B$h$j$A$g$C$H=E$$$N$G!"e(B
e$B%9%T!<%I68E*$K$O%$%d$=$&$G$7$?$1$Ie(B)e$B!#e(B

e$B$5$i$KA0EDe(B(e$B=$8ce(B)e$B$/$s$N;W$$$D$-$K$h$k!Ve(Bloope$B$,e(BStopIteratione$BNce(B
e$B30$rJaB*$9$k!W$H$$$&%"%$%G%#%"$r$?$9$H!"$^$k$G2{$+$7$Ne(BSather
e$B$N$h$&$Ke(B

e = [1,2,3,4,5].each
loop do
p e.next
end

e$B$N$h$&$J$3$H$,$G$-$k$h$&$K$J$j$^$9!#AGE(!#e(B

e$B$G!"<j85$G$O%3!<%G%#%s%0$G$-$A$c$C$?$s$G!"$3$l$+$i%3%_%C%H$7e(B
e$B$h$&$+$J$"!"$H!#H?BP$9$k$J$i:#$N$&$A!#e(B

                            e$B$^$D$b$He(B e$B$f$-$R$me(B /:|)

e$BA0ED$G$9!#e(B

On 08/24/2007 07:39 PM, Yusuke ENDOH wrote:

Sather e$B$OCN$j$^$;$s$7<B:][email protected]$O$I$&$+$o$+$j$^$;$s$,!">e$NNc$Oe(B
e$B$+$C$3$$$$$G$9$M!#e(Brescue e$B$7$J$/$F$$$$$7!#e(B

e$B>[email protected]$HIaDL$Ke(Beache$B$K%V%m%C%/EO$;$P$$$$$8$c$s$H$$$&46$8$G$9$,!"e(B
Sathere$BIw$Ne(Bloope$B$G$&$l$7$$$N$OJ#?t$Ne(BEnumeratore$B$rJB9T$7$F=hM}$9$ke(B
e$B;~$K0J2<$N$h$&$K=q$1$k$3$H$G$9!#e(B

e1 = [1,2,3,4,5].each
e2 = [“a”,“b”,“c”,“d”,“e”].each

loop do
p [e1.next, e2.next]
end

e$B=PNO$O0J2<$N$h$&$K$J$j$^$9!#e(B

[1, “a”]
[2, “b”]
[3, “c”]
[4, “d”]
[5, “e”]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs