summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2008-09-26 21:05:54 (GMT)
committerdgp <dgp@users.sourceforge.net>2008-09-26 21:05:54 (GMT)
commit11a39b96c6ee19beca3ef9583139c4a8377bcaa9 (patch)
treeac5ee07fdd2aa2dae014ee703f1ad89e20eb22d8
parent03fe58895ff5d2fff94410b80ecf3fd7907b7948 (diff)
downloadtcl-11a39b96c6ee19beca3ef9583139c4a8377bcaa9.zip
tcl-11a39b96c6ee19beca3ef9583139c4a8377bcaa9.tar.gz
tcl-11a39b96c6ee19beca3ef9583139c4a8377bcaa9.tar.bz2
TIP #323 IMPLEMENTATION (partial)
* doc/lrepeat.n: Revise [lrepeat] to accept both zero * generic/tclCmdIL.c: repetitions and zero elements to be repeated. * tests/lrepeat.test:
-rw-r--r--ChangeLog4
-rw-r--r--doc/lrepeat.n15
-rw-r--r--generic/tclCmdIL.c18
-rw-r--r--tests/lrepeat.test22
4 files changed, 33 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index cbf1c85..b45d8e5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,10 @@
TIP #323 IMPLEMENTATION (partial)
+ * doc/lrepeat.n: Revise [lrepeat] to accept both zero
+ * generic/tclCmdIL.c: repetitions and zero elements to be repeated.
+ * tests/lrepeat.test:
+
* doc/object.n: Revise standard oo method [my variable] to
* generic/tclOOBasic.c: accept zero variable names.
* tests/oo.test:
diff --git a/doc/lrepeat.n b/doc/lrepeat.n
index 3088848..a8141e0 100644
--- a/doc/lrepeat.n
+++ b/doc/lrepeat.n
@@ -4,7 +4,7 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: lrepeat.n,v 1.6 2007/12/13 15:22:32 dgp Exp $
+'\" RCS: @(#) $Id: lrepeat.n,v 1.7 2008/09/26 21:05:57 dgp Exp $
'\"
.so man.macros
.TH lrepeat n 8.5 Tcl "Tcl Built-In Commands"
@@ -13,16 +13,15 @@
.SH NAME
lrepeat \- Build a list by repeating elements
.SH SYNOPSIS
-\fBlrepeat \fInumber element1 \fR?\fIelement2 element3 ...\fR?
+\fBlrepeat \fIcount \fR?\fIelement ...\fR?
.BE
.SH DESCRIPTION
.PP
-The \fBlrepeat\fR command creates a list of size \fInumber * number of
-elements\fR by repeating \fInumber\fR times the sequence of elements
-\fIelement1 element2 ...\fR. \fInumber\fR must be a positive integer,
-\fIelementn\fR can be any Tcl value. Note that \fBlrepeat 1 arg ...\fR
-is identical to \fBlist arg ...\fR, though the \fIarg\fR is required
-with \fBlrepeat\fR.
+The \fBlrepeat\fR command creates a list of size \fIcount * number of
+elements\fR by repeating \fIcount\fR times the sequence of elements
+\fIelement ...\fR. \fIcount\fR must be a non-negative integer,
+\fIelement\fR can be any Tcl value. Note that \fBlrepeat 1 element ...\fR
+is identical to \fBlist element ...\fR.
.SH EXAMPLES
.CS
\fBlrepeat\fR 3 a
diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c
index e1e15e1..99a6cb5 100644
--- a/generic/tclCmdIL.c
+++ b/generic/tclCmdIL.c
@@ -16,7 +16,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclCmdIL.c,v 1.152 2008/09/26 19:12:42 dgp Exp $
+ * RCS: @(#) $Id: tclCmdIL.c,v 1.153 2008/09/26 21:05:57 dgp Exp $
*/
#include "tclInt.h"
@@ -2443,25 +2443,25 @@ Tcl_LrepeatObjCmd(
register Tcl_Obj *const objv[])
/* The argument objects. */
{
- int elementCount, i, result;
+ int elementCount, i;
Tcl_Obj *listPtr, **dataArray;
List *listRepPtr;
/*
* Check arguments for legality:
- * lrepeat posInt value ?value ...?
+ * lrepeat count ?value ...?
*/
- if (objc < 3) {
- Tcl_WrongNumArgs(interp, 1, objv, "positiveCount value ?value ...?");
+ if (objc < 2) {
+ Tcl_WrongNumArgs(interp, 1, objv, "count ?value ...?");
return TCL_ERROR;
}
- result = TclGetIntFromObj(interp, objv[1], &elementCount);
- if (result == TCL_ERROR) {
+ if (TCL_OK != TclGetIntFromObj(interp, objv[1], &elementCount)) {
return TCL_ERROR;
}
- if (elementCount < 1) {
- Tcl_AppendResult(interp, "must have a count of at least 1", NULL);
+ if (elementCount < 0) {
+ Tcl_SetObjResult(interp, Tcl_Format(NULL,
+ "bad count \"%d\": must be integer >= 0", 1, objv+1));
return TCL_ERROR;
}
diff --git a/tests/lrepeat.test b/tests/lrepeat.test
index f6888b1..a28dd27 100644
--- a/tests/lrepeat.test
+++ b/tests/lrepeat.test
@@ -9,7 +9,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: lrepeat.test,v 1.2 2003/10/06 14:32:22 dgp Exp $
+# RCS: @(#) $Id: lrepeat.test,v 1.3 2008/09/26 21:05:57 dgp Exp $
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest 2
@@ -22,14 +22,13 @@ test lrepeat-1.1 {error cases} {
lrepeat
}
-returnCodes 1
- -result {wrong # args: should be "lrepeat positiveCount value ?value ...?"}
+ -result {wrong # args: should be "lrepeat count ?value ...?"}
}
-test lrepeat-1.2 {error cases} {
+test lrepeat-1.2 {Accept zero elements(TIP 323)} {
-body {
lrepeat 1
}
- -returnCodes 1
- -result {wrong # args: should be "lrepeat positiveCount value ?value ...?"}
+ -result {}
}
test lrepeat-1.3 {error cases} {
-body {
@@ -43,14 +42,13 @@ test lrepeat-1.4 {error cases} {
lrepeat -3 1
}
-returnCodes 1
- -result {must have a count of at least 1}
+ -result {bad count "-3": must be integer >= 0}
}
-test lrepeat-1.5 {error cases} {
+test lrepeat-1.5 {Accept zero repetitions (TIP 323)} {
-body {
lrepeat 0
}
- -returnCodes 1
- -result {wrong # args: should be "lrepeat positiveCount value ?value ...?"}
+ -result {}
}
test lrepeat-1.6 {error cases} {
-body {
@@ -59,6 +57,12 @@ test lrepeat-1.6 {error cases} {
-returnCodes 1
-result {expected integer but got "3.5"}
}
+test lrepeat-1.7 {Accept zero repetitions (TIP 323)} {
+ -body {
+ lrepeat 0 a b c
+ }
+ -result {}
+}
## Okay
test lrepeat-2.1 {normal cases} {