# Callcc and Enumerable#each\_with\_index

**URL:** <https://www.ruby-forum.com/t/callcc-and-enumerable-each-with-index/105501>\
**Category:** Development\
**Created:** [May 30, 2007, 2:56pm UTC](https://www.ruby-forum.com/t/callcc-and-enumerable-each-with-index/105501 "2007-05-30T14:56:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sheepman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d07c76/32.png) [@sheepman](https://www.ruby-forum.com/u/sheepman)\
**Post date:** [May 30, 2007, 2:56pm UTC](https://www.ruby-forum.com/t/callcc-and-enumerable-each-with-index/105501/1 "2007-05-30T14:56:47Z")

</div>

e$B$3$s$P$s$O!"e(Bsheepman e$B$G$9!#e(B

callcc e$B$He(B Enumerable#each\_with\_index e$B$r$$$C$7$g$K;H$&$He(B  
index e$B$,$\*$+$7$/$J$j$^$9!#e(B

$ cat t.rb  
vv = 0  
[1, 2, 3].each\_with\_index{|i, idx|  
callcc {|k| $k = k} if i == 2  
vv += 1  
p [vv, idx]  
}  
$k.call if vv \< 7

$ ruby-1.9 t.rb  
[1, 0]  
[2, 1]  
[3, 2]  
[4, 1]  
[5, 4]  
[6, 1]  
[7, 6]

e$B0J2\<$O%Q%C%A$G$9!#e(B

# $ svn diff enum.c Index: enum.c

## — enum.c (revision 12415) +++ enum.c (working copy) @@ -1167,11 +1167,10 @@ each\_with\_index\_i(VALUE val, VALUE memo) { long n;

- VALUE idx = RARRAY\_PTR(memo)[1];  
RARRAY\_PTR(memo)[0] = val;  
rb\_yield(memo);

- val = RARRAY\_PTR(memo)[1];
- n = NUM2LONG(val);

- n = NUM2LONG(idx);  
n++;  
RARRAY\_PTR(memo)[1] = INT2NUM(n);  
return Qnil;

---

<div class="post-metadata">

**Author:** ![sheepman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d07c76/32.png) [@sheepman](https://www.ruby-forum.com/u/sheepman)\
**Post date:** [May 31, 2007, 7:08pm UTC](https://www.ruby-forum.com/t/callcc-and-enumerable-each-with-index/105501/2 "2007-05-31T19:08:46Z")

</div>

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

In message “Re: [ruby-dev:30846] callcc and Enumerable#each\_with\_index”  
on Wed, 30 May 2007 21:55:19 +0900, sheepman  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|callcc e$B$He(B Enumerable#each\_with\_index e$B$r$$$C$7$g$K;H$&$He(B  
|index e$B$,$\*$+$7$/$J$j$^$9!#e(B

e$B%Q%C%A$"$j$,$H$&$4$6$$$^$7$?!#$5$-$[$I\<h$j9~$\_$^$7$?!#e(B
