("a".."f").step(2) {|x| p x}


#1

string e$B$Ne(B range e$B$Ne(B step
e$B$G0z?t$,8z$+$J$$$h$&$K;W$$$^$9!#e(B

% ./ruby -ve ‘(“a”…“f”).step(2) {|x| p x}’
ruby 1.9.0 (2007-06-15 patchlevel 0) [i686-linux]
“a”
“b”
“c”
“d”
“e”
“f”

1.8 e$B$@$H!"0J2<$N$h$&$K0[$J$k7k2L$K$J$j$^$9!#e(B

% ruby-1.8 -ve ‘(“a”…“f”).step(2) {|x| p x}’
ruby 1.8.6 (2007-04-24 patchlevel 5000) [i686-linux]
“a”
“c”
“e”


#2

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

In message “Re: [ruby-dev:31002] (“a”…“f”).step(2) {|x| p x}”
on Fri, 15 Jun 2007 20:23:39 +0900, Tanaka A. removed_email_address@domain.invalid
writes:
|
|string e$B$Ne(B range e$B$Ne(B step e$B$G0z?t$,8z$+$J$$$h$&$K;W$$$^$9!#e(B
|
|% ./ruby -ve ‘(“a”…“f”).step(2) {|x| p x}’
|ruby 1.9.0 (2007-06-15 patchlevel 0) [i686-linux]

rb_iterate()e$B$K$J$s$i$+$NLdBj$,$"$C$F!“e(Bbl_proce$B$KEO$7$?4X?t$Ge(B
e$B$O$J$/!”$=$N30B&$N%V%m%C%/$rD>@\8F$s$G$7$^$C$F$$$k$h$&$G$9!#e(B
e$B$,!“e(BYARV coree$B$N;EAH$_$O$h$/$o$+$i$:!”$=$l0J>e$ODI$($^$;$s$Ge(B
e$B$7$?!#e(B

|1.8 e$B$@$H!"0J2<$N$h$&$K0[$J$k7k2L$K$J$j$^$9!#e(B

e$B$3$A$i$Oe(Bbl_proc(e$B$3$N>l9g$Oe(Bstep_ie$B4X?te(B)e$B$,8F$P$l$F%U%#%k%?%j%se(B
e$B%0$7$F$/$l$F$$$^$9!#e(B


#3

e$B!!$5$5$@$G$9!#e(B

Yukihiro M. wrote:

e$B$,!“e(BYARV coree$B$N;EAH$_$O$h$/$o$+$i$:!”$=$l0J>e$ODI$($^$;$s$Ge(B
e$B$7$?!#e(B

e$B!!LdBj$,$"$k$H$$$&$+!"$R$H$D$N%9%?%C%/%U%l!<%`$K$Oe(B 1 e$B$D$N%Ve(B
e$B%m%C%/EO$7$7$+BP1~$7$F$$$^$;$s!#$3$l$O!"$=$s$J$KJQ$J@)8B$G$O$Je(B
e$B$$$H;W$$$^$9!#e(B

e$B!!$J$N$G!“e(BString#upto e$B$re(B funcall
e$B$G8F$s$G$b$i$&I,MW$,$”$j$^e(B
e$B$9!#$?$@!“e(Bexcl
e$B$rEO$9J}K!$,$J$$$N$G!”$I$&$7$?$b$s$@$+G:$s$G$$e(B
e$B$^$7$?!#e(B


#4

In article removed_email_address@domain.invalid,
SASADA Koichi removed_email_address@domain.invalid writes:

e$B!!LdBj$,$"$k$H$$$&$+!"$R$H$D$N%9%?%C%/%U%l!<%`$K$Oe(B 1 e$B$D$N%Ve(B
e$B%m%C%/EO$7$7$+BP1~$7$F$$$^$;$s!#$3$l$O!"$=$s$J$KJQ$J@)8B$G$O$Je(B
e$B$$$H;W$$$^$9!#e(B

e$B!!$J$N$G!“e(BString#upto e$B$re(B funcall e$B$G8F$s$G$b$i$&I,MW$,$”$j$^e(B
e$B$9!#$?$@!“e(Bexcl e$B$rEO$9J}K!$,$J$$$N$G!”$I$&$7$?$b$s$@$+G:$s$G$$e(B
e$B$^$7$?!#e(B

e$B$h$/$o$+$C$F$$$^$;$s$,!"e(Brb_iterate() e$B$Oe(B YARV
e$B$G$O<B8=$5$l$Je(B
e$B$$$H$$$&0UL#$G$9$+e(B?


#5

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

In message “Re: [ruby-dev:31009] Re: (“a”…“f”).step(2) {|x| p x}”
on Sat, 16 Jun 2007 12:38:00 +0900, SASADA Koichi removed_email_address@domain.invalid
writes:

|> |string e$B$Ne(B range e$B$Ne(B step e$B$G0z?t$,8z$+$J$$$h$&$K;W$$$^$9!#e(B
|> |
|> |% ./ruby -ve ‘(“a”…“f”).step(2) {|x| p x}’
|> |ruby 1.9.0 (2007-06-15 patchlevel 0) [i686-linux]
|>
|> rb_iterate()e$B$K$J$s$i$+$NLdBj$,$"$C$F!“e(Bbl_proce$B$KEO$7$?4X?t$Ge(B
|> e$B$O$J$/!”$=$N30B&$N%V%m%C%/$rD>@\8F$s$G$7$^$C$F$$$k$h$&$G$9!#e(B
|> e$B$,!“e(BYARV coree$B$N;EAH$_$O$h$/$o$+$i$:!”$=$l0J>e$ODI$($^$;$s$Ge(B
|> e$B$7$?!#e(B
|
|e$B!!LdBj$,$"$k$H$$$&$+!"$R$H$D$N%9%?%C%/%U%l!<%`$K$Oe(B 1 e$B$D$N%Ve(B
|e$B%m%C%/EO$7$7$+BP1~$7$F$$$^$;$s!#$3$l$O!"$=$s$J$KJQ$J@)8B$G$O$Je(B
|e$B$$$H;W$$$^$9!#e(B

e$B$4$a$s$J$5$$!#!V$R$H$D$N%9%?%C%/%U%l!<%`$K$Oe(B 1
e$B$D$N%V%m%C%/EOe(B
e$B$7$7$+BP1~$7$F$$$^$;$s!W$H$$$&$N$,$J$K$r0UL#$9$k$N$+$h$/$o$+e(B
e$B$j$^$;$s!#$N$G!“JQ$J@)8B$G$J$$$N$+$I$&$+$NH=CG$b$G$-$^$;$s!#e(B
rb_iterate()e$BA4HL$,F0$+$J$$$H$$$&$o$1$G$O$J$$$h$&$G$9$,!”$?$He(B
e$B$($Pe(Beach_with_indexe$B$,F0$$$Fe(Bstepe$B$,F0$+$J$$M}M3$C$F$N$O$9$0$Ke(B
e$B%T%s$H$OMh$^$;$s$M!#e(B

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

#6

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

Yukihiro M. wrote:

|> rb_iterate()e$B$K$J$s$i$+$NLdBj$,$"$C$F!"e(Bbl_proce$B$KEO$7$?4X?t$Ge(B
e$B$j$^$;$s!#$N$G!“JQ$J@)8B$G$J$$$N$+$I$&$+$NH=CG$b$G$-$^$;$s!#e(B
rb_iterate()e$BA4HL$,F0$+$J$$$H$$$&$o$1$G$O$J$$$h$&$G$9$,!”$?$He(B
e$B$($Pe(Beach_with_indexe$B$,F0$$$Fe(Bstepe$B$,F0$+$J$$M}M3$C$F$N$O$9$0$Ke(B
e$B%T%s$H$OMh$^$;$s$M!#e(B

range_stepe$B$N>l9ge(B str_step -> step_i -> block
e$B$G$J$1$l$P$$$1$J$$$N$K!"e(B
str_step -> block e$B$H$J$C$F$7$^$C$F$$$k$H$$$&$3$H$G$9$+$M!&!&!&!)e(B

e$BDI$C$F$_$k$H!"e(B
range_step
rb_iterate(str_step, (VALUE)args, step_i, (VALUE)iter);
rb_iterate(VALUE (*it_proc) (VALUE), VALUE data1,
VALUE (*bl_proc) (ANYARGS), VALUE data2)
NODE *node = NEW_IFUNC(bl_proc, data2);
blockptr->iseq = (void *)node;
th->passed_block = blockptr;
retval = (*it_proc) (data1);

th_call0(rb_thread_t *th, VALUE klass, VALUE recv,
VALUE id, ID oid, int argc, const VALUE *argv,
NODE * body, int nosuper)
if (th->passed_block) {
blockptr = th->passed_block;
th->passed_block = 0;
}
push_frame(th, 0, FRAME_MAGIC_CFUNC,
recv, (VALUE)blockptr, 0, reg_cfp->sp, 0, 1);
val = call_cfunc(body->nd_cfnc, recv, body->nd_argc, argc, argv);
e$B$H$J$j!"e(Bbl_proc
e$B$,%U%l!<%`$K@Q$^$l$F$$$k$h$&$K8+$($F!"8F$P$l$F$O$$$J$$!)e(B
e$B$I$&$b40A4$Ke(B rb_iterate e$B$,5!G=$7$F$$$J$$5$$,$9$k$N$G$9$,!#e(B

e$B$H$j$"$($:$Oe(B str_step e$B$re(B rb_str_upto e$B$He(B step_i
e$B$rAH$9g$o$;$k$N$G$J$/!"e(B
rb_str_step e$B$r;H$&$h$&$K$7$F$
$k$H$+$I$&$G$7$g$&!#e(B

Index: string.c

— string.c (revision 12561)
+++ string.c (working copy)
@@ -1575,7 +1575,38 @@
return beg;
}

+VALUE
+rb_str_step(VALUE beg, VALUE end, int excl, int unit)
+{

  • VALUE current, after_end;

  • ID succ = rb_intern(“succ”);

  • int n;

  • int iter = 1;

  • StringValue(end);

  • n = rb_str_cmp(beg, end);

  • if (n > 0 || (excl && n == 0)) return beg;

  • after_end = rb_funcall(end, succ, 0, 0);

  • current = beg;

  • while (!rb_str_equal(current, after_end)) {

  • iter–;

  • if (iter == 0) {

  •  iter = unit;
    
  •  rb_yield(current);
    
  • }

  • if (!excl && rb_str_equal(current, end)) break;

  • current = rb_funcall(current, succ, 0, 0);

  • StringValue(current);

  • if (excl && rb_str_equal(current, end)) break;

  • StringValue(current);

  • if (RSTRING_LEN(current) > RSTRING_LEN(end) || RSTRING_LEN(current)
    == 0)

  •  break;
    
  • }

  • return beg;
    +}

/*

  • call-seq:
  • str.upto(other_str) {|s| block }   => str
    

Index: range.c

— range.c (revision 12561)
+++ range.c (working copy)
@@ -223,7 +223,7 @@
{
VALUE *args = (VALUE *)arg;

  • return rb_str_upto(args[0], args[1], EXCL(args[2]));
  • return rb_str_step(args[0], args[1], EXCL(args[2]), args[3]);
    }

static void
@@ -330,9 +330,8 @@
args[0] = b;
args[1] = e;
args[2] = range;

  •  iter[0] = 1;
    
  •  iter[1] = unit;
    
  •  rb_iterate(str_step, (VALUE)args, step_i, (VALUE)iter);
    
  •  args[3] = unit;
    
  •  (*str_step)((VALUE)args);
    
    }
    else if (rb_obj_is_kind_of(b, rb_cNumeric)) {
    ID c = rb_intern(EXCL(range) ? “<” : “<=”);

#7

In article removed_email_address@domain.invalid,
SASADA Koichi removed_email_address@domain.invalid writes:

e$BCG$7$^$7$?!J$F$C$-$j!“e(B(2) e$B$N;H$$J}$@$1$+$H;W$C$F$$$?!K!#e(B(1) e$B$Ke(B
e$B0MB8$7$?%W%m%0%i%`$C$F$I$l$/$i$$$”$k$G$7$g$&$+!#D>$9$N$O7k9=Bge(B
e$BJQ$=$&$G$9!#e(B

e$B$=$&$$$&5?Ld$r;}$C$?$H$-$O%3!<%I8!:w$G$O$J$$$G$7$g$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(Bexcle$B$rEO$9J}K!$,$J$$$s$@$1$I!K!#e(B


#9

e$B!!$5$5$@$G$9!#e(B

NARUSE, Yui wrote:

e$B!!$J$N$G!"8=:_$Ne(B rb_iterate() e$B$N;EMM$K$h$k2r7hJ}K!$Oe(B
str_step() e$B$Ge(B rb_funcall() e$B$G2?$i$+$N%a%=%C%I$r8F$Y$P$h$$$H$$e(B
e$B$&$3$H$K$J$j$^$9!#e(B

e$B$3$l$C$F!"0lEYe(B Ruby e$B$NAX$^$G>e$i$J$$e(B bl_proc e$B$,8F$P$l$J$$$H$$$&$3$H$G$9e(B
e$B$h$M!#e(Bit_proc e$B$[$I$G$O$J$$$K$7$F$b!"e(Bbl_proc e$B$N$h$&$K2?EY$b8F$P$l$kItJ,$,e(B
e$BI,$:e(B Ruby e$BAX7PM3$H$$$&$N$O>/$75$$K$J$j$^$9!#e(B

e$B!!!Ve(BRubye$BAX!W$NDj5A$,$J$$$N$G$o$+$j$^$;$s$,!"$H$j$"$($:e(B VM
e$B$N%9e(B
e$B%?%C%/%U%l!<%`$r@Q$s$G$M!"$H$$$&46$8$G$9!#e(B

rb_define_method(rb_cString, “upto_excl”, rb_str_upto, 2);
e$B$H$G$bDj5A$7$F!"e(Bstr_step e$B$+$ie(B
return rb_funcall(args[0], rb_intern(“upto_excl”), 2, args[1],
EXCL(args[2]));
e$B$H8F$Y$P$$$$$N$G$9$+$M!#e(B
e$B$J$s$+>iD9$J5$$O$7$^$9$,!#e(B

e$B!!2r7h:v$O!"$^$!$=$s$J46$8$G$9!#e(B


#10

e$B@.@%$G$9!#e(B

SASADA Koichi wrote:

e$B!!$5$5$@$G$9!#e(B

e$B!!@.@%$5$s!"%=!<%9$rFI$s$G$/$l$F$"$j$,$H$&$4$6$$$^$7$?!#$3$3$Ge(B
e$BBg;v$J$N$Oe(B rb_iterate e$B$KEO$94X?t$+$ie(B rb_call0 e$B$,8F$P$l$F$$$J$$e(B
e$B$H$$$&$3$H$G$9!#e(B

rb_call0 e$B$Oe(B 1.9 e$B$G$OB8:_$7$^$;$s$,!"e(Bth_call0
e$B$G$9$h$M!#$J$k$[$I!"K\Mh$Oe(B
rb_funcall e$B7PM3$Ge(B th_call0
e$B$,8F$P$l$k$O$:$@$C$?$N$G$9$+!"DL$j$G%=!<%9e(B
e$BDI$C$F$b$?$I$jCe$+$J$$$o$1$@!&!&!&!#e(B

e$BJQ$=$&$G$9!#e(B

e$B!!$J$N$G!"8=:_$Ne(B rb_iterate() e$B$N;EMM$K$h$k2r7hJ}K!$Oe(B
str_step() e$B$Ge(B rb_funcall() e$B$G2?$i$+$N%a%=%C%I$r8F$Y$P$h$$$H$$e(B
e$B$&$3$H$K$J$j$^$9!#e(B

e$B$3$l$C$F!"0lEYe(B Ruby e$B$NAX$^$G>e$i$J$$e(B bl_proc
e$B$,8F$P$l$J$$$H$$$&$3$H$G$9e(B
e$B$h$M!#e(Bit_proc e$B$[$I$G$O$J$$$K$7$F$b!"e(Bbl_proc
e$B$N$h$&$K2?EY$b8F$P$l$kItJ,$,e(B
e$BI,$:e(B Ruby e$BAX7PM3$H$$$&$N$O>/$75$$K$J$j$^$9!#e(B

e$B$H$$$&$3$H$K$J$j$^$9!#$?$H$($P!“e(BRange#step e$B$,e(B String#step e$B$r8Fe(B
e$B$S=P$;$P!”@5$7$/F0$-$^$9!Je(Bexcle$B$rEO$9J}K!$,$J$$$s$@$1$I!K!#e(B

rb_define_method(rb_cString, “upto_excl”, rb_str_upto, 2);
e$B$H$G$bDj5A$7$F!"e(Bstr_step e$B$+$ie(B
return rb_funcall(args[0], rb_intern(“upto_excl”), 2, args[1],
EXCL(args[2]));
e$B$H8F$Y$P$$$$$N$G$9$+$M!#e(B
e$B$J$s$+>iD9$J5$$O$7$^$9$,!#e(B


#11

e$B!!$5$5$@$G$9!#e(B

Tanaka A. wrote:

e$BCG$7$^$7$?!J$F$C$-$j!“e(B(2) e$B$N;H$$J}$@$1$+$H;W$C$F$$$?!K!#e(B(1) e$B$Ke(B
e$B0MB8$7$?%W%m%0%i%`$C$F$I$l$/$i$$$”$k$G$7$g$&$+!#D>$9$N$O7k9=Bge(B
e$BJQ$=$&$G$9!#e(B

e$B$=$&$$$&5?Ld$r;}$C$?$H$-$O%3!<%I8!:w$G$O$J$$$G$7$g$&$+!#e(B

e$B!!$H$j$"$($:!"8=:_e(B trunk e$BCf$G$O!“e(Brb_iterate
e$B<+?H$rMxMQ$7$F$$$ke(B
e$B%3!<%I$,>/$J$$!Je(Brb_block_call
e$B$r;H$&$h$&$K$J$C$F$$$k!K$7!”;H$Ce(B
e$B$F$$$F$be(B rb_each e$B!J$3$$$D$O!"e(Brb_funcall(:each)
e$B$r$9$k$N$GLdBje(B
e$B$J$$!K$rEO$7$F$$$k$h$&$G$9!#e(B

e$B!!e(BRAA e$B$Ne(B gonzui
e$B$G$b!“8!:w>e0L$7$+8+$F$$$J$$$N$G$9$,!”$?$V$se(B
e$B;H$C$F$$$J$$$h$&$K;W$$$^$7$?!#e(B