In article <1020155811.294677.24806.nullmailer / picachu.netlab.jp>, Yukihiro Matsumoto wrote:
> Agrred.  They will be merged.  Thank you.

	Great!
	
	Here is the patch that applies clearly to current Ruby...

		Michal


Index: range.c
===================================================================
RCS file: /src/ruby/range.c,v
retrieving revision 1.32
diff -u -r1.32 range.c
--- range.c	2002/04/24 04:54:14	1.32
+++ range.c	2002/04/30 08:44:46
@@ -78,7 +78,7 @@
 	rb_name_error(rb_intern("initialized"), "`initialize' called twice");
     }
     range_init(obj, beg, end, RTEST(flags));
-    return Qnil;
+    return obj;
 }
 
 static VALUE
@@ -231,59 +231,6 @@
 }
 
 static VALUE
-range_each(range)
-    VALUE range;
-{
-    VALUE b, e;
-
-    b = rb_ivar_get(range, id_beg);
-    e = rb_ivar_get(range, id_end);
-
-    if (FIXNUM_P(b) && FIXNUM_P(e)) { /* fixnums are special */
-	long end = FIX2LONG(e);
-	long i;
-
-	if (!EXCL(range)) end += 1;
-	for (i=FIX2LONG(b); i<end; i++) {
-	    rb_yield(INT2NUM(i));
-	}
-    }
-    else if (TYPE(b) == T_STRING) {
-	rb_str_upto(b, e, EXCL(range));
-    }
-    else if (rb_obj_is_kind_of(b, rb_cNumeric)) {
-	b = rb_Integer(b);
-	e = rb_Integer(e);
-
-	if (!EXCL(range)) e = rb_funcall(e, '+', 1, INT2FIX(1));
-	while (RTEST(rb_funcall(b, '<', 1, e))) {
-	    rb_yield(b);
-	    b = rb_funcall(b, '+', 1, INT2FIX(1));
-	}
-    }
-    else {			/* generic each */
-	VALUE v = b;
-
-	if (EXCL(range)) {
-	    while (r_lt(v, e)) {
-		if (r_eq(v, e)) break;
-		rb_yield(v);
-		v = rb_funcall(v, id_succ, 0, 0);
-	    }
-	}
-	else {
-	    while (r_le(v, e)) {
-		rb_yield(v);
-		if (r_eq(v, e)) break;
-		v = rb_funcall(v, id_succ, 0, 0);
-	    }
-	}
-    }
-
-    return range;
-}
-
-static VALUE
 r_step_str(args)
     VALUE *args;
 {
@@ -313,12 +260,16 @@
 
     b = rb_ivar_get(range, id_beg);
     e = rb_ivar_get(range, id_end);
-    rb_scan_args(argc, argv, "01", &step);
+    if (rb_scan_args(argc, argv, "01", &step) == 0) {
+	step = INT2FIX(1);
+    }
 
     if (FIXNUM_P(b) && FIXNUM_P(e)) { /* fixnums are special */
-	long end = FIX2LONG(e);
-	long i, s = (argc == 0) ? 1 : NUM2LONG(step);
-
+	long end = FIX2LONG(e), s = NUM2LONG(step);
+	long i;
+	if (s <= 0) {
+	    rb_raise(rb_eArgError, "step cannot be <= 0");
+	}
 	if (!EXCL(range)) end += 1;
 	for (i=FIX2LONG(b); i<end; i+=s) {
 	    rb_yield(INT2NUM(i));
@@ -329,6 +280,9 @@
 	e = rb_Integer(e);
 	step = rb_Integer(step);
 
+	if (RTEST(rb_funcall(step, rb_intern("<="), INT2FIX(0)))) {
+	    rb_raise(rb_eArgError, "step cannot be <= 0");
+	}
 	if (!EXCL(range)) e = rb_funcall(e, '+', 1, INT2FIX(1));
 	while (RTEST(rb_funcall(b, '<', 1, e))) {
 	    rb_yield(b);
@@ -346,7 +300,7 @@
     }
     else {			/* generic each */
 	VALUE v = b;
-	long lim = NUM2INT(step);
+	long lim = NUM2LONG(step);
 	long i;
 
 	if (EXCL(range)) {
@@ -367,6 +321,14 @@
 	}
     }
 
+    return range;
+}
+
+static VALUE
+range_each(range)
+    VALUE range;
+{
+    range_step(0, NULL, range);
     return range;
 }
 
-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Michal Rokos                         Czech Technical University, Prague
E-mail:m.rokos / sh.cvut.cz  ICQ:36118339  Jabber:majkl / jabber.sh.cvut.cz
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-