-- cgit v0.12 From c0481e830577e5c171081870edce6c95d6f6ef87 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Sun, 7 Aug 2022 07:16:38 +0000 Subject: TIP 631 - lsubst command --- generic/tclBasic.c | 1 + generic/tclCmdIL.c | 117 +++++++++++++++++++++ generic/tclInt.h | 3 + tests/lreplace.test | 295 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 416 insertions(+) diff --git a/generic/tclBasic.c b/generic/tclBasic.c index a0c5a91..f7e0929 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -324,6 +324,7 @@ static const CmdInfo builtInCmds[] = { {"lsearch", Tcl_LsearchObjCmd, NULL, NULL, CMD_IS_SAFE}, {"lset", Tcl_LsetObjCmd, TclCompileLsetCmd, NULL, CMD_IS_SAFE}, {"lsort", Tcl_LsortObjCmd, NULL, NULL, CMD_IS_SAFE}, + {"lsubst", Tcl_LsubstObjCmd, NULL, NULL, CMD_IS_SAFE}, {"package", Tcl_PackageObjCmd, NULL, TclNRPackageObjCmd, CMD_IS_SAFE}, {"proc", Tcl_ProcObjCmd, NULL, NULL, CMD_IS_SAFE}, {"regexp", Tcl_RegexpObjCmd, TclCompileRegexpCmd, NULL, CMD_IS_SAFE}, diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index cdc302c..7776c78 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -4486,6 +4486,123 @@ Tcl_LsortObjCmd( /* *---------------------------------------------------------------------- * + * Tcl_LsubstObjCmd -- + * + * This procedure is invoked to process the "lsubst" Tcl command. See the + * user documentation for details on what it does. + * + * Results: + * A standard Tcl result. + * + * Side effects: + * See the user documentation. + * + *---------------------------------------------------------------------- + */ + +int +Tcl_LsubstObjCmd( + TCL_UNUSED(ClientData), + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const objv[]) /* Argument values. */ +{ + Tcl_Obj *listPtr; /* Pointer to the list being altered. */ + Tcl_Obj *finalValuePtr; /* Value finally assigned to the variable. */ + int createdNewObj; + int result; + int first; + int last; + int listLen; + int numToDelete; + + if (objc < 4) { + Tcl_WrongNumArgs(interp, 1, objv, + "listVar first last ?element ...?"); + return TCL_ERROR; + } + + listPtr = Tcl_ObjGetVar2(interp, objv[1], NULL, TCL_LEAVE_ERR_MSG); + if (listPtr == NULL) { + return TCL_ERROR; + } + + /* + * TODO - refactor the index extraction into a common function shared + * by Tcl_{Lrange,Lreplace,Lsubst}ObjCmd + */ + + result = TclListObjLengthM(interp, listPtr, &listLen); + if (result != TCL_OK) { + return result; + } + + result = TclGetIntForIndexM(interp, objv[2], /*end*/ listLen-1, &first); + if (result != TCL_OK) { + return result; + } + + result = TclGetIntForIndexM(interp, objv[3], /*end*/ listLen-1, &last); + if (result != TCL_OK) { + return result; + } + + if (first == TCL_INDEX_NONE) { + first = 0; + } else if (first > listLen) { + first = listLen; + } + + if (last >= listLen) { + last = listLen - 1; + } + if (first <= last) { + numToDelete = last - first + 1; + } else { + numToDelete = 0; + } + + if (Tcl_IsShared(listPtr)) { + listPtr = TclListObjCopy(NULL, listPtr); + createdNewObj = 1; + } else { + createdNewObj = 0; + } + + result = + Tcl_ListObjReplace(interp, listPtr, first, numToDelete, objc - 4, objv + 4); + if (result != TCL_OK) { + if (createdNewObj) { + Tcl_DecrRefCount(listPtr); + } + return result; + } + + /* + * Tcl_ObjSetVar2 mau return a value different from listPtr in the + * presence of traces etc.. Note that finalValuePtr will always have a + * reference count of at least 1 corresponding to the reference from the + * var. If it is same as listPtr, then ref count will be at least 2 + * since we are incr'ing the latter below (safer when calling + * Tcl_ObjSetVar2 which can release it in some cases). Note that we + * leave the incrref of listPtr this late because we want to pass it as + * unshared to Tcl_ListObjReplace above if possible. + */ + Tcl_IncrRefCount(listPtr); + finalValuePtr = + Tcl_ObjSetVar2(interp, objv[1], NULL, listPtr, TCL_LEAVE_ERR_MSG); + Tcl_DecrRefCount(listPtr); /* safe irrespective of createdNewObj */ + if (finalValuePtr == NULL) { + return TCL_ERROR; + } + + Tcl_SetObjResult(interp, finalValuePtr); + return TCL_OK; +} + +/* + *---------------------------------------------------------------------- + * * MergeLists - * * This procedure combines two sorted lists of SortElement structures diff --git a/generic/tclInt.h b/generic/tclInt.h index 06ec2ad..562140c 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -3711,6 +3711,9 @@ MODULE_SCOPE int Tcl_LsetObjCmd(ClientData clientData, MODULE_SCOPE int Tcl_LsortObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_LsubstObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); MODULE_SCOPE Tcl_Command TclInitNamespaceCmd(Tcl_Interp *interp); MODULE_SCOPE int TclNamespaceEnsembleCmd(ClientData dummy, Tcl_Interp *interp, int objc, diff --git a/tests/lreplace.test b/tests/lreplace.test index 0b26e86..4204c2f 100644 --- a/tests/lreplace.test +++ b/tests/lreplace.test @@ -236,6 +236,301 @@ apply {{} { } }} +# Essentially same tests as above but for lsubst +test lsubst-1.1 {lsubst command} { + set l {1 2 3 4 5} + list [lsubst l 0 0 a] $l +} {{a 2 3 4 5} {a 2 3 4 5}} +test lsubst-1.2 {lsubst command} { + set l {1 2 3 4 5} + list [lsubst l 1 1 a] $l +} {{1 a 3 4 5} {1 a 3 4 5}} +test lsubst-1.3 {lsubst command} { + set l {1 2 3 4 5} + list [lsubst l 2 2 a] $l +} {{1 2 a 4 5} {1 2 a 4 5}} +test lsubst-1.4 {lsubst command} { + set l {1 2 3 4 5} + list [lsubst l 3 3 a] $l +} {{1 2 3 a 5} {1 2 3 a 5}} +test lsubst-1.5 {lsubst command} { + set l {1 2 3 4 5} + list [lsubst l 4 4 a] $l +} {{1 2 3 4 a} {1 2 3 4 a}} +test lsubst-1.6 {lsubst command} { + set l {1 2 3 4 5} + list [lsubst l 4 5 a] $l +} {{1 2 3 4 a} {1 2 3 4 a}} +test lsubst-1.7 {lsubst command} { + set l {1 2 3 4 5} + list [lsubst l -1 -1 a] $l +} {{a 1 2 3 4 5} {a 1 2 3 4 5}} +test lsubst-1.8 {lsubst command} { + set l {1 2 3 4 5} + list [lsubst l 2 end a b c d] $l +} {{1 2 a b c d} {1 2 a b c d}} +test lsubst-1.9 {lsubst command} { + set l {1 2 3 4 5} + list [lsubst l 0 3] $l +} {5 5} +test lsubst-1.10 {lsubst command} { + set l {1 2 3 4 5} + list [lsubst l 0 4] $l +} {{} {}} +test lsubst-1.11 {lsubst command} { + set l {1 2 3 4 5} + list [lsubst l 0 1] $l +} {{3 4 5} {3 4 5}} +test lsubst-1.12 {lsubst command} { + set l {1 2 3 4 5} + list [lsubst l 2 3] $l +} {{1 2 5} {1 2 5}} +test lsubst-1.13 {lsubst command} { + set l {1 2 3 4 5} + list [lsubst l 3 end] $l +} {{1 2 3} {1 2 3}} +test lsubst-1.14 {lsubst command} { + set l {1 2 3 4 5} + list [lsubst l -1 4 a b c] $l +} {{a b c} {a b c}} +test lsubst-1.15 {lsubst command} { + set l {a b "c c" d e f} + list [lsubst l 3 3] $l +} {{a b {c c} e f} {a b {c c} e f}} +test lsubst-1.16 {lsubst command} { + set l { 1 2 3 4 5} + list [lsubst l 0 0 a] $l +} {{a 2 3 4 5} {a 2 3 4 5}} +test lsubst-1.17 {lsubst command} { + set l {1 2 3 4 "5 6"} + list [lsubst l 4 4 a] $l +} {{1 2 3 4 a} {1 2 3 4 a}} +test lsubst-1.18 {lsubst command} { + set l {1 2 3 4 {5 6}} + list [lsubst l 4 4 a] $l +} {{1 2 3 4 a} {1 2 3 4 a}} +test lsubst-1.19 {lsubst command} { + set l {1 2 3 4} + list [lsubst l 2 end x y z] $l +} {{1 2 x y z} {1 2 x y z}} +test lsubst-1.20 {lsubst command} { + set l {1 2 3 4} + list [lsubst l end end a] $l +} {{1 2 3 a} {1 2 3 a}} +test lsubst-1.21 {lsubst command} { + set l {1 2 3 4} + list [lsubst l end 3 a] $l +} {{1 2 3 a} {1 2 3 a}} +test lsubst-1.22 {lsubst command} { + set l {1 2 3 4} + list [lsubst l end end] $l +} {{1 2 3} {1 2 3}} +test lsubst-1.23 {lsubst command} { + set l {1 2 3 4} + list [lsubst l 2 -1 xy] $l +} {{1 2 xy 3 4} {1 2 xy 3 4}} +test lsubst-1.24 {lsubst command} { + set l {1 2 3 4} + list [lsubst l end -1 z] $l +} {{1 2 3 z 4} {1 2 3 z 4}} +test lsubst-1.25 {lsubst command} { + set l {\}\ hello} + concat \"[lsubst l end end]\" $l +} {"\}\ " \}\ } +test lsubst-1.26 {lsubst command} { + catch {unset foo} + set foo {a b} + list [lsubst foo end end] $foo \ + [lsubst foo end end] $foo \ + [lsubst foo end end] $foo +} {a a {} {} {} {}} +test lsubst-1.27 {lsubset command} -body { + set l x + list [lsubst l 1 1] $l +} -result {x x} +test lsubst-1.28 {lsubst command} -body { + set l x + list [lsubst l 1 1 y] $l +} -result {{x y} {x y}} +test lsubst-1.29 {lsubst command} -body { + set l x + lsubst l 1 1 [error foo] +} -returnCodes 1 -result {foo} +test lsubst-1.30 {lsubst command} -body { + set l {not {}alist} + lsubst l 0 0 [error foo] +} -returnCodes 1 -result {foo} +test lsubst-1.31 {lsubst command} -body { + unset -nocomplain arr + set arr(x) {a b} + list [lsubst arr(x) 0 0 c] $arr(x) +} -result {{c b} {c b}} + +test lsubst-2.1 {lsubst errors} -body { + list [catch lsubst msg] $msg +} -result {1 {wrong # args: should be "lsubst listVar first last ?element ...?"}} +test lsubst-2.2 {lsubst errors} -body { + unset -nocomplain x + list [catch {lsubst l b} msg] $msg +} -result {1 {wrong # args: should be "lsubst listVar first last ?element ...?"}} +test lsubst-2.3 {lsubst errors} -body { + set x {} + list [catch {lsubst x a 10} msg] $msg +} -result {1 {bad index "a": must be integer?[+-]integer? or end?[+-]integer?}} +test lsubst-2.4 {lsubst errors} -body { + set l {} + list [catch {lsubst l 10 x} msg] $msg +} -result {1 {bad index "x": must be integer?[+-]integer? or end?[+-]integer?}} +test lsubst-2.5 {lsubst errors} -body { + set l {} + list [catch {lsubst l 10 1x} msg] $msg +} -result {1 {bad index "1x": must be integer?[+-]integer? or end?[+-]integer?}} +test lsubst-2.6 {lsubst errors} -body { + set l x + list [catch {lsubst l 3 2} msg] $msg +} -result {0 x} +test lsubst-2.7 {lsubst errors} -body { + set l x + list [catch {lsubst l 2 2} msg] $msg +} -result {0 x} +test lsubst-2.8 {lsubst errors} -body { + unset -nocomplain l + lsubst l 0 0 x +} -returnCodes error -result {can't read "l": no such variable} +test lsubst-2.9 {lsubst errors} -body { + unset -nocomplain arr + lsubst arr(x) 0 0 x +} -returnCodes error -result {can't read "arr(x)": no such variable} +test lsubst-2.10 {lsubst errors} -body { + unset -nocomplain arr + set arr(y) y + lsubst arr(x) 0 0 x +} -returnCodes error -result {can't read "arr(x)": no such element in array} + +test lsubst-3.1 {lsubst won't modify shared argument objects} { + proc p {} { + set l "a b c" + lsubst l 1 1 "x y" + # The literal in locals table should be unmodified + return [list "a b c" $l] + } + p +} {{a b c} {a {x y} c}} + +# Following bugs were in lreplace. Make sure lsubst does not have them +test lsubst-4.1 {Bug ccc2c2cc98: lreplace edge case} { + set l {} + list [lsubst l 1 1] $l +} {{} {}} +test lsubst-4.2 {Bug ccc2c2cc98: lreplace edge case} { + set l { } + list [lsubst l 1 1] $l +} {{} {}} +test lsubst-4.3 {lreplace edge case} { + set l {1 2 3} + lsubst l 2 0 +} {1 2 3} +test lsubst-4.4 {lsubst edge case} { + set l {1 2 3 4 5} + list [lsubst l 3 1] $l +} {{1 2 3 4 5} {1 2 3 4 5}} +test lreplace-4.5 {lreplace edge case} { + lreplace {1 2 3 4 5} 3 0 _ +} {1 2 3 _ 4 5} +test lsubst-4.6 {lsubst end-x: bug a4cb3f06c4} { + set l {0 1 2 3 4} + list [lsubst l 0 end-2] $l +} {{3 4} {3 4}} +test lsubst-4.6.1 {lsubst end-x: bug a4cb3f06c4} { + set l {0 1 2 3 4} + list [lsubst l 0 end-2 a b c] $l +} {{a b c 3 4} {a b c 3 4}} +test lsubst-4.7 {lsubst with two end-indexes: increasing} { + set l {0 1 2 3 4} + list [lsubst l end-2 end-1] $l +} {{0 1 4} {0 1 4}} +test lsubst-4.7.1 {lsubst with two end-indexes: increasing} { + set l {0 1 2 3 4} + list [lsubst l end-2 end-1 a b c] $l +} {{0 1 a b c 4} {0 1 a b c 4}} +test lsubst-4.8 {lsubst with two end-indexes: equal} { + set l {0 1 2 3 4} + list [lsubst l end-2 end-2] $l +} {{0 1 3 4} {0 1 3 4}} +test lsubst-4.8.1 {lsubst with two end-indexes: equal} { + set l {0 1 2 3 4} + list [lsubst l end-2 end-2 a b c] $l +} {{0 1 a b c 3 4} {0 1 a b c 3 4}} +test lsubst-4.9 {lsubst with two end-indexes: decreasing} { + set l {0 1 2 3 4} + list [lsubst l end-2 end-3] $l +} {{0 1 2 3 4} {0 1 2 3 4}} +test lsubst-4.9.1 {lsubst with two end-indexes: decreasing} { + set l {0 1 2 3 4} + list [lsubst l end-2 end-3 a b c] $l +} {{0 1 a b c 2 3 4} {0 1 a b c 2 3 4}} +test lsubst-4.10 {lsubst with two equal indexes} { + set l {0 1 2 3 4} + list [lsubst l 2 2] $l +} {{0 1 3 4} {0 1 3 4}} +test lsubst-4.10.1 {lsubst with two equal indexes} { + set l {0 1 2 3 4} + list [lsubst l 2 2 a b c] $l +} {{0 1 a b c 3 4} {0 1 a b c 3 4}} +test lsubst-4.11 {lsubst end index first} { + set l {0 1 2 3 4} + list [lsubst l end-2 1 a b c] $l +} {{0 1 a b c 2 3 4} {0 1 a b c 2 3 4}} +test lsubst-4.12 {lsubst end index first} { + set l {0 1 2 3 4} + list [lsubst l end-2 2 a b c] $l +} {{0 1 a b c 3 4} {0 1 a b c 3 4}} +test lsubst-4.13 {lsubst empty list} { + set l {} + list [lsubst l 1 1 1] $l +} {1 1} +test lsubst-4.14 {lsubst empty list} { + set l {} + list [lsubst l 2 2 2] $l +} {2 2} + +test lsubst-5.1 {compiled lreplace: Bug 47ac84309b} { + apply {x { + lsubst x end 0 + }} {a b c} +} {a b c} +test lsubst-5.2 {compiled lreplace: Bug 47ac84309b} { + apply {x { + lsubst x end 0 A + }} {a b c} +} {a b A c} + +# Testing for compiled behaviour. Far too many variations to check with +# spelt-out tests. Note that this *just* checks whether the compiled version +# and the interpreted version are the same, not whether the interpreted +# version is correct. +apply {{} { + set lss {{} {a} {a b c} {a b c d}} + set ins {{} A {A B}} + set idxs {-2 -1 0 1 2 3 end-3 end-2 end-1 end end+1 end+2} + set lreplace lreplace + + foreach ls $lss { + foreach a $idxs { + foreach b $idxs { + foreach i $ins { + set expected [list [catch {$lreplace $ls $a $b {*}$i} m] $m] + set tester [list lsubst ls $a $b {*}$i] + set script [list catch $tester m] + set script "list \[$script\] \$m" + test lsubst-6.[incr n] {lsubst battery} -body \ + [list apply [list {ls} $script] $ls] -result $expected + } + } + } + } +}} + # cleanup catch {unset foo} ::tcltest::cleanupTests -- cgit v0.12 From 0c5c7cc5eb0499b1b4f2b9000364ebe52186adf5 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Fri, 16 Sep 2022 07:29:15 +0000 Subject: Rename lsubst to ledit, add docs --- doc/interp.n | 20 ++-- doc/lappend.n | 2 +- doc/lassign.n | 2 +- doc/ledit.n | 91 ++++++++++++++++++ doc/lindex.n | 2 +- doc/linsert.n | 2 +- doc/list.n | 2 +- doc/llength.n | 2 +- doc/lmap.n | 2 +- doc/lpop.n | 2 +- doc/lrange.n | 2 +- doc/lremove.n | 2 +- doc/lrepeat.n | 2 +- doc/lreplace.n | 2 +- doc/lreverse.n | 2 +- doc/lsearch.n | 2 +- doc/lset.n | 2 +- doc/lsort.n | 2 +- generic/tclBasic.c | 2 +- generic/tclCmdIL.c | 8 +- generic/tclInt.h | 6 +- tests/lreplace.test | 264 ++++++++++++++++++++++++++-------------------------- 22 files changed, 257 insertions(+), 166 deletions(-) create mode 100644 doc/ledit.n diff --git a/doc/interp.n b/doc/interp.n index 2943404..b3cc918 100644 --- a/doc/interp.n +++ b/doc/interp.n @@ -591,16 +591,16 @@ built-in commands: \fBflush\fR \fBfor\fR \fBforeach\fR \fBformat\fR \fBgets\fR \fBglobal\fR \fBif\fR \fBincr\fR \fBinfo\fR \fBinterp\fR \fBjoin\fR \fBlappend\fR -\fBlassign\fR \fBlindex\fR \fBlinsert\fR \fBlist\fR -\fBllength\fR \fBlrange\fR \fBlrepeat\fR \fBlreplace\fR -\fBlsearch\fR \fBlset\fR \fBlsort\fR \fBnamespace\fR -\fBpackage\fR \fBpid\fR \fBproc\fR \fBputs\fR -\fBread\fR \fBregexp\fR \fBregsub\fR \fBrename\fR -\fBreturn\fR \fBscan\fR \fBseek\fR \fBset\fR -\fBsplit\fR \fBstring\fR \fBsubst\fR \fBswitch\fR -\fBtell\fR \fBtime\fR \fBtrace\fR \fBunset\fR -\fBupdate\fR \fBuplevel\fR \fBupvar\fR \fBvariable\fR -\fBvwait\fR \fBwhile\fR +\fBlassign\fR \fBledit\fR \fBlindex\fR \fBlinsert\fR +\fBlist\fR \fBllength\fR \fBlrange\fR \fBlrepeat\fR +\fBlreplace\fR \fBlsearch\fR \fBlset\fR \fBlsort\fR +\fBnamespace\fR \fBpackage\fR \fBpid\fR \fBproc\fR +\fBputs\fR \fBread\fR \fBregexp\fR \fBregsub\fR +\fBrename\fR \fBreturn\fR \fBscan\fR \fBseek\fR +\fBset\fR \fBsplit\fR \fBstring\fR \fBsubst\fR +\fBswitch\fR \fBtell\fR \fBtime\fR \fBtrace\fR +\fBunset\fR \fBupdate\fR \fBuplevel\fR \fBupvar\fR +\fBvariable\fR \fBvwait\fR \fBwhile\fR .DE The following commands are hidden by \fBinterp create\fR when it creates a safe interpreter: diff --git a/doc/lappend.n b/doc/lappend.n index 89b6909..3ddb36c 100644 --- a/doc/lappend.n +++ b/doc/lappend.n @@ -49,7 +49,7 @@ Using \fBlappend\fR to build up a list of numbers. 1 2 3 4 5 .CE .SH "SEE ALSO" -list(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS diff --git a/doc/lassign.n b/doc/lassign.n index 67048ba..ac53322 100644 --- a/doc/lassign.n +++ b/doc/lassign.n @@ -52,7 +52,7 @@ command in many shell languages like this: set ::argv [\fBlassign\fR $::argv argumentToReadOff] .CE .SH "SEE ALSO" -list(n), lappend(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS diff --git a/doc/ledit.n b/doc/ledit.n new file mode 100644 index 0000000..f7704ed --- /dev/null +++ b/doc/ledit.n @@ -0,0 +1,91 @@ +'\" +'\" Copyright (c) 2022 Ashok P. Nadkarni . All rights reserved. +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.TH ledit n 8.7 Tcl "Tcl Built-In Commands" +.so man.macros +.BS +'\" Note: do not modify the .SH NAME line immediately below! +.SH NAME +ledit \- Replace elements of a list stored in variable +.SH SYNOPSIS +\fBledit \fIlistVar first last \fR?\fIvalue value ...\fR? +.BE +.SH DESCRIPTION +.PP +The command fetches the list value in variable \fIlistVar\fR and replaces the +elements in the range given by indices \fIfirst\fR to \fIlast\fR (inclusive) +with the \fIvalue\fR arguments. The resulting list is then stored back in +\fIlistVar\fR and returned as the result of the command. +.PP +Arguments \fIfirst\fR and \fIlast\fR are index values specifying the first and +last elements of the range to replace. They are interpreted +the same as index values for the command \fBstring index\fR, +supporting simple index arithmetic and indices relative to the +end of the list. The index 0 refers to the first element of the +list, and \fBend\fR refers to the last element of the list. +.PP +If either \fIfirst\fR or \fIlast\fR is less than zero, it is considered to +refer to the position before the first element of the list. This allows +elements to be prepended. +.PP +If either \fIfirst\fR or \fIlast\fR indicates a position greater than the +index of the last element of the list, it is treated as if it is an +index one greater than the last element. This allows elements to be appended. +.PP +If \fIlast\fR is less than \fIfirst\fR, then any specified elements +will be inserted into the list before the element specified by \fIfirst\fR +with no elements being deleted. +.PP +The \fIvalue\fR arguments specify zero or more new elements to +be added to the list in place of those that were deleted. +Each \fIvalue\fR argument will become a separate element of +the list. If no \fIvalue\fR arguments are specified, then the elements +between \fIfirst\fR and \fIlast\fR are simply deleted. +.SH EXAMPLES +.PP +Prepend to a list. +.PP +.CS +% set lst {c d e f g} +c d e f g +% ledit lst -1 -1 a b +a b c d e f g +.CE +.PP +Append to the list. +.PP +.CS +% ledit lst end+1 end+1 h i +a b c d e f g h i +.CE +.PP +Delete third and fourth elements. +.PP +.CS +% ledit lst 2 3 +a b e f g h i +.CE +.PP +Replace two elements with three. +.PP +.CS +% ledit lst 2 3 x y z +a b x y z g h i +% set lst +a b x y z g h i +.CE +.PP +.SH "SEE ALSO" +list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), +lreverse(n), lsearch(n), lset(n), lsort(n), +string(n) +.SH KEYWORDS +element, list, replace +.\" Local variables: +.\" mode: nroff +.\" fill-column: 78 +.\" End: diff --git a/doc/lindex.n b/doc/lindex.n index 75fe5e8..0ba30a4 100644 --- a/doc/lindex.n +++ b/doc/lindex.n @@ -115,7 +115,7 @@ set idx 3 \fI\(-> f\fR .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n), string(n) diff --git a/doc/linsert.n b/doc/linsert.n index 3179256..685b563 100644 --- a/doc/linsert.n +++ b/doc/linsert.n @@ -45,7 +45,7 @@ set newList [\fBlinsert\fR $midList end-1 lazy] set newerList [\fBlinsert\fR [\fBlinsert\fR $oldList end-1 quick] 1 lazy] .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n), string(n) diff --git a/doc/list.n b/doc/list.n index 3fa1975..1792560 100644 --- a/doc/list.n +++ b/doc/list.n @@ -46,7 +46,7 @@ while \fBconcat\fR with the same arguments will return \fBa b c d e f {g h}\fR .CE .SH "SEE ALSO" -lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS diff --git a/doc/llength.n b/doc/llength.n index 26824a0..7a3e6de 100644 --- a/doc/llength.n +++ b/doc/llength.n @@ -49,7 +49,7 @@ An empty list is not necessarily an empty string: 1,0 .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS diff --git a/doc/lmap.n b/doc/lmap.n index 026e9d0..29b1242 100644 --- a/doc/lmap.n +++ b/doc/lmap.n @@ -78,7 +78,7 @@ set prefix [\fBlmap\fR x $values {expr { .CE .SH "SEE ALSO" break(n), continue(n), for(n), foreach(n), while(n), -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS diff --git a/doc/lpop.n b/doc/lpop.n index 3d88638..0a156ee 100644 --- a/doc/lpop.n +++ b/doc/lpop.n @@ -86,7 +86,7 @@ The indicated value becomes the new value of \fIx\fR. \fI\(-> {{a b} {c d}} {{e f} h}\fR .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n), string(n) diff --git a/doc/lrange.n b/doc/lrange.n index 0d4b261..c0434bb 100644 --- a/doc/lrange.n +++ b/doc/lrange.n @@ -71,7 +71,7 @@ elements to {elements to} .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n), string(n) diff --git a/doc/lremove.n b/doc/lremove.n index 59d261b..e71f607 100644 --- a/doc/lremove.n +++ b/doc/lremove.n @@ -46,7 +46,7 @@ Removing the same element indicated in two different ways: a b d e .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS diff --git a/doc/lrepeat.n b/doc/lrepeat.n index 9a3fc88..de7ba54 100644 --- a/doc/lrepeat.n +++ b/doc/lrepeat.n @@ -32,7 +32,7 @@ is identical to \fBlist element ...\fR. \fI\(-> {a a} b c {a a} b c {a a} b c\fR .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS diff --git a/doc/lreplace.n b/doc/lreplace.n index bc9d7ca..6694ad7 100644 --- a/doc/lreplace.n +++ b/doc/lreplace.n @@ -95,7 +95,7 @@ a b c d e f g h i .CE .VE TIP505 .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreverse(n), lsearch(n), lset(n), lsort(n), string(n) diff --git a/doc/lreverse.n b/doc/lreverse.n index e2e3b69..0f0b6d6 100644 --- a/doc/lreverse.n +++ b/doc/lreverse.n @@ -25,7 +25,7 @@ input list, \fIlist\fR, except with the elements in the reverse order. \fI\(-> f e {c d} b a\fR .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS diff --git a/doc/lsearch.n b/doc/lsearch.n index c5dc98f..85b8609 100644 --- a/doc/lsearch.n +++ b/doc/lsearch.n @@ -229,7 +229,7 @@ The same thing for a flattened list: .CE .SH "SEE ALSO" foreach(n), -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lset(n), lsort(n), string(n) diff --git a/doc/lset.n b/doc/lset.n index 4b97ed6..588a0a5 100644 --- a/doc/lset.n +++ b/doc/lset.n @@ -136,7 +136,7 @@ The indicated return value also becomes the new value of \fIx\fR. \fI\(-> {{a b} {c d}} {{e f} {j h}}\fR .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lsort(n) string(n) diff --git a/doc/lsort.n b/doc/lsort.n index 2018e30..ddf9ed1 100644 --- a/doc/lsort.n +++ b/doc/lsort.n @@ -264,7 +264,7 @@ More complex sorting using a comparison function: {1 dingo} {2 banana} {0x2 carrot} {3 apple} .CE .SH "SEE ALSO" -list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), +list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), lreverse(n), lsearch(n), lset(n) .SH KEYWORDS diff --git a/generic/tclBasic.c b/generic/tclBasic.c index b013909..21503b4 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -324,7 +324,7 @@ static const CmdInfo builtInCmds[] = { {"lsearch", Tcl_LsearchObjCmd, NULL, NULL, CMD_IS_SAFE}, {"lset", Tcl_LsetObjCmd, TclCompileLsetCmd, NULL, CMD_IS_SAFE}, {"lsort", Tcl_LsortObjCmd, NULL, NULL, CMD_IS_SAFE}, - {"lsubst", Tcl_LsubstObjCmd, NULL, NULL, CMD_IS_SAFE}, + {"ledit", Tcl_LeditObjCmd, NULL, NULL, CMD_IS_SAFE}, {"package", Tcl_PackageObjCmd, NULL, TclNRPackageObjCmd, CMD_IS_SAFE}, {"proc", Tcl_ProcObjCmd, NULL, NULL, CMD_IS_SAFE}, {"regexp", Tcl_RegexpObjCmd, TclCompileRegexpCmd, NULL, CMD_IS_SAFE}, diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index 7776c78..b2e3ac8 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -4486,9 +4486,9 @@ Tcl_LsortObjCmd( /* *---------------------------------------------------------------------- * - * Tcl_LsubstObjCmd -- + * Tcl_LeditObjCmd -- * - * This procedure is invoked to process the "lsubst" Tcl command. See the + * This procedure is invoked to process the "ledit" Tcl command. See the * user documentation for details on what it does. * * Results: @@ -4501,7 +4501,7 @@ Tcl_LsortObjCmd( */ int -Tcl_LsubstObjCmd( +Tcl_LeditObjCmd( TCL_UNUSED(ClientData), Tcl_Interp *interp, /* Current interpreter. */ int objc, /* Number of arguments. */ @@ -4529,7 +4529,7 @@ Tcl_LsubstObjCmd( /* * TODO - refactor the index extraction into a common function shared - * by Tcl_{Lrange,Lreplace,Lsubst}ObjCmd + * by Tcl_{Lrange,Lreplace,Ledit}ObjCmd */ result = TclListObjLengthM(interp, listPtr, &listLen); diff --git a/generic/tclInt.h b/generic/tclInt.h index 155bb82..863251b 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -3686,6 +3686,9 @@ MODULE_SCOPE int Tcl_LappendObjCmd(void *clientData, MODULE_SCOPE int Tcl_LassignObjCmd(void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); +MODULE_SCOPE int Tcl_LeditObjCmd(ClientData clientData, + Tcl_Interp *interp, int objc, + Tcl_Obj *const objv[]); MODULE_SCOPE int Tcl_LindexObjCmd(void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); @@ -3731,9 +3734,6 @@ MODULE_SCOPE int Tcl_LsetObjCmd(void *clientData, MODULE_SCOPE int Tcl_LsortObjCmd(void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); -MODULE_SCOPE int Tcl_LsubstObjCmd(ClientData clientData, - Tcl_Interp *interp, int objc, - Tcl_Obj *const objv[]); MODULE_SCOPE Tcl_Command TclInitNamespaceCmd(Tcl_Interp *interp); MODULE_SCOPE int TclNamespaceEnsembleCmd(void *dummy, Tcl_Interp *interp, int objc, diff --git a/tests/lreplace.test b/tests/lreplace.test index 4204c2f..2952899 100644 --- a/tests/lreplace.test +++ b/tests/lreplace.test @@ -236,272 +236,272 @@ apply {{} { } }} -# Essentially same tests as above but for lsubst -test lsubst-1.1 {lsubst command} { +# Essentially same tests as above but for ledit +test ledit-1.1 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 0 0 a] $l + list [ledit l 0 0 a] $l } {{a 2 3 4 5} {a 2 3 4 5}} -test lsubst-1.2 {lsubst command} { +test ledit-1.2 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 1 1 a] $l + list [ledit l 1 1 a] $l } {{1 a 3 4 5} {1 a 3 4 5}} -test lsubst-1.3 {lsubst command} { +test ledit-1.3 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 2 2 a] $l + list [ledit l 2 2 a] $l } {{1 2 a 4 5} {1 2 a 4 5}} -test lsubst-1.4 {lsubst command} { +test ledit-1.4 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 3 3 a] $l + list [ledit l 3 3 a] $l } {{1 2 3 a 5} {1 2 3 a 5}} -test lsubst-1.5 {lsubst command} { +test ledit-1.5 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 4 4 a] $l + list [ledit l 4 4 a] $l } {{1 2 3 4 a} {1 2 3 4 a}} -test lsubst-1.6 {lsubst command} { +test ledit-1.6 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 4 5 a] $l + list [ledit l 4 5 a] $l } {{1 2 3 4 a} {1 2 3 4 a}} -test lsubst-1.7 {lsubst command} { +test ledit-1.7 {ledit command} { set l {1 2 3 4 5} - list [lsubst l -1 -1 a] $l + list [ledit l -1 -1 a] $l } {{a 1 2 3 4 5} {a 1 2 3 4 5}} -test lsubst-1.8 {lsubst command} { +test ledit-1.8 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 2 end a b c d] $l + list [ledit l 2 end a b c d] $l } {{1 2 a b c d} {1 2 a b c d}} -test lsubst-1.9 {lsubst command} { +test ledit-1.9 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 0 3] $l + list [ledit l 0 3] $l } {5 5} -test lsubst-1.10 {lsubst command} { +test ledit-1.10 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 0 4] $l + list [ledit l 0 4] $l } {{} {}} -test lsubst-1.11 {lsubst command} { +test ledit-1.11 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 0 1] $l + list [ledit l 0 1] $l } {{3 4 5} {3 4 5}} -test lsubst-1.12 {lsubst command} { +test ledit-1.12 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 2 3] $l + list [ledit l 2 3] $l } {{1 2 5} {1 2 5}} -test lsubst-1.13 {lsubst command} { +test ledit-1.13 {ledit command} { set l {1 2 3 4 5} - list [lsubst l 3 end] $l + list [ledit l 3 end] $l } {{1 2 3} {1 2 3}} -test lsubst-1.14 {lsubst command} { +test ledit-1.14 {ledit command} { set l {1 2 3 4 5} - list [lsubst l -1 4 a b c] $l + list [ledit l -1 4 a b c] $l } {{a b c} {a b c}} -test lsubst-1.15 {lsubst command} { +test ledit-1.15 {ledit command} { set l {a b "c c" d e f} - list [lsubst l 3 3] $l + list [ledit l 3 3] $l } {{a b {c c} e f} {a b {c c} e f}} -test lsubst-1.16 {lsubst command} { +test ledit-1.16 {ledit command} { set l { 1 2 3 4 5} - list [lsubst l 0 0 a] $l + list [ledit l 0 0 a] $l } {{a 2 3 4 5} {a 2 3 4 5}} -test lsubst-1.17 {lsubst command} { +test ledit-1.17 {ledit command} { set l {1 2 3 4 "5 6"} - list [lsubst l 4 4 a] $l + list [ledit l 4 4 a] $l } {{1 2 3 4 a} {1 2 3 4 a}} -test lsubst-1.18 {lsubst command} { +test ledit-1.18 {ledit command} { set l {1 2 3 4 {5 6}} - list [lsubst l 4 4 a] $l + list [ledit l 4 4 a] $l } {{1 2 3 4 a} {1 2 3 4 a}} -test lsubst-1.19 {lsubst command} { +test ledit-1.19 {ledit command} { set l {1 2 3 4} - list [lsubst l 2 end x y z] $l + list [ledit l 2 end x y z] $l } {{1 2 x y z} {1 2 x y z}} -test lsubst-1.20 {lsubst command} { +test ledit-1.20 {ledit command} { set l {1 2 3 4} - list [lsubst l end end a] $l + list [ledit l end end a] $l } {{1 2 3 a} {1 2 3 a}} -test lsubst-1.21 {lsubst command} { +test ledit-1.21 {ledit command} { set l {1 2 3 4} - list [lsubst l end 3 a] $l + list [ledit l end 3 a] $l } {{1 2 3 a} {1 2 3 a}} -test lsubst-1.22 {lsubst command} { +test ledit-1.22 {ledit command} { set l {1 2 3 4} - list [lsubst l end end] $l + list [ledit l end end] $l } {{1 2 3} {1 2 3}} -test lsubst-1.23 {lsubst command} { +test ledit-1.23 {ledit command} { set l {1 2 3 4} - list [lsubst l 2 -1 xy] $l + list [ledit l 2 -1 xy] $l } {{1 2 xy 3 4} {1 2 xy 3 4}} -test lsubst-1.24 {lsubst command} { +test ledit-1.24 {ledit command} { set l {1 2 3 4} - list [lsubst l end -1 z] $l + list [ledit l end -1 z] $l } {{1 2 3 z 4} {1 2 3 z 4}} -test lsubst-1.25 {lsubst command} { +test ledit-1.25 {ledit command} { set l {\}\ hello} - concat \"[lsubst l end end]\" $l + concat \"[ledit l end end]\" $l } {"\}\ " \}\ } -test lsubst-1.26 {lsubst command} { +test ledit-1.26 {ledit command} { catch {unset foo} set foo {a b} - list [lsubst foo end end] $foo \ - [lsubst foo end end] $foo \ - [lsubst foo end end] $foo + list [ledit foo end end] $foo \ + [ledit foo end end] $foo \ + [ledit foo end end] $foo } {a a {} {} {} {}} -test lsubst-1.27 {lsubset command} -body { +test ledit-1.27 {lsubset command} -body { set l x - list [lsubst l 1 1] $l + list [ledit l 1 1] $l } -result {x x} -test lsubst-1.28 {lsubst command} -body { +test ledit-1.28 {ledit command} -body { set l x - list [lsubst l 1 1 y] $l + list [ledit l 1 1 y] $l } -result {{x y} {x y}} -test lsubst-1.29 {lsubst command} -body { +test ledit-1.29 {ledit command} -body { set l x - lsubst l 1 1 [error foo] + ledit l 1 1 [error foo] } -returnCodes 1 -result {foo} -test lsubst-1.30 {lsubst command} -body { +test ledit-1.30 {ledit command} -body { set l {not {}alist} - lsubst l 0 0 [error foo] + ledit l 0 0 [error foo] } -returnCodes 1 -result {foo} -test lsubst-1.31 {lsubst command} -body { +test ledit-1.31 {ledit command} -body { unset -nocomplain arr set arr(x) {a b} - list [lsubst arr(x) 0 0 c] $arr(x) + list [ledit arr(x) 0 0 c] $arr(x) } -result {{c b} {c b}} -test lsubst-2.1 {lsubst errors} -body { - list [catch lsubst msg] $msg -} -result {1 {wrong # args: should be "lsubst listVar first last ?element ...?"}} -test lsubst-2.2 {lsubst errors} -body { +test ledit-2.1 {ledit errors} -body { + list [catch ledit msg] $msg +} -result {1 {wrong # args: should be "ledit listVar first last ?element ...?"}} +test ledit-2.2 {ledit errors} -body { unset -nocomplain x - list [catch {lsubst l b} msg] $msg -} -result {1 {wrong # args: should be "lsubst listVar first last ?element ...?"}} -test lsubst-2.3 {lsubst errors} -body { + list [catch {ledit l b} msg] $msg +} -result {1 {wrong # args: should be "ledit listVar first last ?element ...?"}} +test ledit-2.3 {ledit errors} -body { set x {} - list [catch {lsubst x a 10} msg] $msg + list [catch {ledit x a 10} msg] $msg } -result {1 {bad index "a": must be integer?[+-]integer? or end?[+-]integer?}} -test lsubst-2.4 {lsubst errors} -body { +test ledit-2.4 {ledit errors} -body { set l {} - list [catch {lsubst l 10 x} msg] $msg + list [catch {ledit l 10 x} msg] $msg } -result {1 {bad index "x": must be integer?[+-]integer? or end?[+-]integer?}} -test lsubst-2.5 {lsubst errors} -body { +test ledit-2.5 {ledit errors} -body { set l {} - list [catch {lsubst l 10 1x} msg] $msg + list [catch {ledit l 10 1x} msg] $msg } -result {1 {bad index "1x": must be integer?[+-]integer? or end?[+-]integer?}} -test lsubst-2.6 {lsubst errors} -body { +test ledit-2.6 {ledit errors} -body { set l x - list [catch {lsubst l 3 2} msg] $msg + list [catch {ledit l 3 2} msg] $msg } -result {0 x} -test lsubst-2.7 {lsubst errors} -body { +test ledit-2.7 {ledit errors} -body { set l x - list [catch {lsubst l 2 2} msg] $msg + list [catch {ledit l 2 2} msg] $msg } -result {0 x} -test lsubst-2.8 {lsubst errors} -body { +test ledit-2.8 {ledit errors} -body { unset -nocomplain l - lsubst l 0 0 x + ledit l 0 0 x } -returnCodes error -result {can't read "l": no such variable} -test lsubst-2.9 {lsubst errors} -body { +test ledit-2.9 {ledit errors} -body { unset -nocomplain arr - lsubst arr(x) 0 0 x + ledit arr(x) 0 0 x } -returnCodes error -result {can't read "arr(x)": no such variable} -test lsubst-2.10 {lsubst errors} -body { +test ledit-2.10 {ledit errors} -body { unset -nocomplain arr set arr(y) y - lsubst arr(x) 0 0 x + ledit arr(x) 0 0 x } -returnCodes error -result {can't read "arr(x)": no such element in array} -test lsubst-3.1 {lsubst won't modify shared argument objects} { +test ledit-3.1 {ledit won't modify shared argument objects} { proc p {} { set l "a b c" - lsubst l 1 1 "x y" + ledit l 1 1 "x y" # The literal in locals table should be unmodified return [list "a b c" $l] } p } {{a b c} {a {x y} c}} -# Following bugs were in lreplace. Make sure lsubst does not have them -test lsubst-4.1 {Bug ccc2c2cc98: lreplace edge case} { +# Following bugs were in lreplace. Make sure ledit does not have them +test ledit-4.1 {Bug ccc2c2cc98: lreplace edge case} { set l {} - list [lsubst l 1 1] $l + list [ledit l 1 1] $l } {{} {}} -test lsubst-4.2 {Bug ccc2c2cc98: lreplace edge case} { +test ledit-4.2 {Bug ccc2c2cc98: lreplace edge case} { set l { } - list [lsubst l 1 1] $l + list [ledit l 1 1] $l } {{} {}} -test lsubst-4.3 {lreplace edge case} { +test ledit-4.3 {lreplace edge case} { set l {1 2 3} - lsubst l 2 0 + ledit l 2 0 } {1 2 3} -test lsubst-4.4 {lsubst edge case} { +test ledit-4.4 {ledit edge case} { set l {1 2 3 4 5} - list [lsubst l 3 1] $l + list [ledit l 3 1] $l } {{1 2 3 4 5} {1 2 3 4 5}} test lreplace-4.5 {lreplace edge case} { lreplace {1 2 3 4 5} 3 0 _ } {1 2 3 _ 4 5} -test lsubst-4.6 {lsubst end-x: bug a4cb3f06c4} { +test ledit-4.6 {ledit end-x: bug a4cb3f06c4} { set l {0 1 2 3 4} - list [lsubst l 0 end-2] $l + list [ledit l 0 end-2] $l } {{3 4} {3 4}} -test lsubst-4.6.1 {lsubst end-x: bug a4cb3f06c4} { +test ledit-4.6.1 {ledit end-x: bug a4cb3f06c4} { set l {0 1 2 3 4} - list [lsubst l 0 end-2 a b c] $l + list [ledit l 0 end-2 a b c] $l } {{a b c 3 4} {a b c 3 4}} -test lsubst-4.7 {lsubst with two end-indexes: increasing} { +test ledit-4.7 {ledit with two end-indexes: increasing} { set l {0 1 2 3 4} - list [lsubst l end-2 end-1] $l + list [ledit l end-2 end-1] $l } {{0 1 4} {0 1 4}} -test lsubst-4.7.1 {lsubst with two end-indexes: increasing} { +test ledit-4.7.1 {ledit with two end-indexes: increasing} { set l {0 1 2 3 4} - list [lsubst l end-2 end-1 a b c] $l + list [ledit l end-2 end-1 a b c] $l } {{0 1 a b c 4} {0 1 a b c 4}} -test lsubst-4.8 {lsubst with two end-indexes: equal} { +test ledit-4.8 {ledit with two end-indexes: equal} { set l {0 1 2 3 4} - list [lsubst l end-2 end-2] $l + list [ledit l end-2 end-2] $l } {{0 1 3 4} {0 1 3 4}} -test lsubst-4.8.1 {lsubst with two end-indexes: equal} { +test ledit-4.8.1 {ledit with two end-indexes: equal} { set l {0 1 2 3 4} - list [lsubst l end-2 end-2 a b c] $l + list [ledit l end-2 end-2 a b c] $l } {{0 1 a b c 3 4} {0 1 a b c 3 4}} -test lsubst-4.9 {lsubst with two end-indexes: decreasing} { +test ledit-4.9 {ledit with two end-indexes: decreasing} { set l {0 1 2 3 4} - list [lsubst l end-2 end-3] $l + list [ledit l end-2 end-3] $l } {{0 1 2 3 4} {0 1 2 3 4}} -test lsubst-4.9.1 {lsubst with two end-indexes: decreasing} { +test ledit-4.9.1 {ledit with two end-indexes: decreasing} { set l {0 1 2 3 4} - list [lsubst l end-2 end-3 a b c] $l + list [ledit l end-2 end-3 a b c] $l } {{0 1 a b c 2 3 4} {0 1 a b c 2 3 4}} -test lsubst-4.10 {lsubst with two equal indexes} { +test ledit-4.10 {ledit with two equal indexes} { set l {0 1 2 3 4} - list [lsubst l 2 2] $l + list [ledit l 2 2] $l } {{0 1 3 4} {0 1 3 4}} -test lsubst-4.10.1 {lsubst with two equal indexes} { +test ledit-4.10.1 {ledit with two equal indexes} { set l {0 1 2 3 4} - list [lsubst l 2 2 a b c] $l + list [ledit l 2 2 a b c] $l } {{0 1 a b c 3 4} {0 1 a b c 3 4}} -test lsubst-4.11 {lsubst end index first} { +test ledit-4.11 {ledit end index first} { set l {0 1 2 3 4} - list [lsubst l end-2 1 a b c] $l + list [ledit l end-2 1 a b c] $l } {{0 1 a b c 2 3 4} {0 1 a b c 2 3 4}} -test lsubst-4.12 {lsubst end index first} { +test ledit-4.12 {ledit end index first} { set l {0 1 2 3 4} - list [lsubst l end-2 2 a b c] $l + list [ledit l end-2 2 a b c] $l } {{0 1 a b c 3 4} {0 1 a b c 3 4}} -test lsubst-4.13 {lsubst empty list} { +test ledit-4.13 {ledit empty list} { set l {} - list [lsubst l 1 1 1] $l + list [ledit l 1 1 1] $l } {1 1} -test lsubst-4.14 {lsubst empty list} { +test ledit-4.14 {ledit empty list} { set l {} - list [lsubst l 2 2 2] $l + list [ledit l 2 2 2] $l } {2 2} -test lsubst-5.1 {compiled lreplace: Bug 47ac84309b} { +test ledit-5.1 {compiled lreplace: Bug 47ac84309b} { apply {x { - lsubst x end 0 + ledit x end 0 }} {a b c} } {a b c} -test lsubst-5.2 {compiled lreplace: Bug 47ac84309b} { +test ledit-5.2 {compiled lreplace: Bug 47ac84309b} { apply {x { - lsubst x end 0 A + ledit x end 0 A }} {a b c} } {a b A c} @@ -520,10 +520,10 @@ apply {{} { foreach b $idxs { foreach i $ins { set expected [list [catch {$lreplace $ls $a $b {*}$i} m] $m] - set tester [list lsubst ls $a $b {*}$i] + set tester [list ledit ls $a $b {*}$i] set script [list catch $tester m] set script "list \[$script\] \$m" - test lsubst-6.[incr n] {lsubst battery} -body \ + test ledit-6.[incr n] {ledit battery} -body \ [list apply [list {ls} $script] $ls] -result $expected } } -- cgit v0.12 From f7d30cbf993a21d1a461c806ded05e3d3fd6ea50 Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Tue, 27 Sep 2022 03:17:28 +0000 Subject: Add lseq to list command cross references --- doc/interp.n | 16 ++++++++-------- doc/lappend.n | 2 +- doc/lassign.n | 2 +- doc/ledit.n | 2 +- doc/lindex.n | 2 +- doc/linsert.n | 2 +- doc/list.n | 2 +- doc/llength.n | 2 +- doc/lmap.n | 2 +- doc/lpop.n | 2 +- doc/lrange.n | 2 +- doc/lremove.n | 2 +- doc/lrepeat.n | 2 +- doc/lreplace.n | 2 +- doc/lreverse.n | 2 +- doc/lsearch.n | 2 +- doc/lseq.n | 4 ++-- doc/lset.n | 2 +- doc/lsort.n | 2 +- 19 files changed, 27 insertions(+), 27 deletions(-) diff --git a/doc/interp.n b/doc/interp.n index b3cc918..08bed1c 100644 --- a/doc/interp.n +++ b/doc/interp.n @@ -593,14 +593,14 @@ built-in commands: \fBinfo\fR \fBinterp\fR \fBjoin\fR \fBlappend\fR \fBlassign\fR \fBledit\fR \fBlindex\fR \fBlinsert\fR \fBlist\fR \fBllength\fR \fBlrange\fR \fBlrepeat\fR -\fBlreplace\fR \fBlsearch\fR \fBlset\fR \fBlsort\fR -\fBnamespace\fR \fBpackage\fR \fBpid\fR \fBproc\fR -\fBputs\fR \fBread\fR \fBregexp\fR \fBregsub\fR -\fBrename\fR \fBreturn\fR \fBscan\fR \fBseek\fR -\fBset\fR \fBsplit\fR \fBstring\fR \fBsubst\fR -\fBswitch\fR \fBtell\fR \fBtime\fR \fBtrace\fR -\fBunset\fR \fBupdate\fR \fBuplevel\fR \fBupvar\fR -\fBvariable\fR \fBvwait\fR \fBwhile\fR +\fBlreplace\fR \fBlsearch\fR \fBlseq\fR \fBlset\fR +\fBlsort\fR \fBnamespace\fR \fBpackage\fR \fBpid\fR +\fBproc\fR \fBputs\fR \fBread\fR \fBregexp\fR +\fBregsub\fR \fBrename\fR \fBreturn\fR \fBscan\fR +\fBseek\fR \fBset\fR \fBsplit\fR \fBstring\fR +\fBsubst\fR \fBswitch\fR \fBtell\fR \fBtime\fR +\fBtrace\fR \fBunset\fR \fBupdate\fR \fBuplevel\fR +\fBupvar\fR \fBvariable\fR \fBvwait\fR \fBwhile\fR .DE The following commands are hidden by \fBinterp create\fR when it creates a safe interpreter: diff --git a/doc/lappend.n b/doc/lappend.n index 3ddb36c..3fbda79 100644 --- a/doc/lappend.n +++ b/doc/lappend.n @@ -51,7 +51,7 @@ Using \fBlappend\fR to build up a list of numbers. .SH "SEE ALSO" list(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), -lreverse(n), lsearch(n), lset(n), lsort(n) +lreverse(n), lsearch(n), lseq(n), lset(n), lsort(n) .SH KEYWORDS append, element, list, variable .\" Local variables: diff --git a/doc/lassign.n b/doc/lassign.n index ac53322..d23509a 100644 --- a/doc/lassign.n +++ b/doc/lassign.n @@ -54,7 +54,7 @@ set ::argv [\fBlassign\fR $::argv argumentToReadOff] .SH "SEE ALSO" list(n), lappend(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), -lreverse(n), lsearch(n), lset(n), lsort(n) +lreverse(n), lsearch(n), lseq(n), lset(n), lsort(n) .SH KEYWORDS assign, element, list, multiple, set, variable '\"Local Variables: diff --git a/doc/ledit.n b/doc/ledit.n index f7704ed..48e6da5 100644 --- a/doc/ledit.n +++ b/doc/ledit.n @@ -81,7 +81,7 @@ a b x y z g h i .SH "SEE ALSO" list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), -lreverse(n), lsearch(n), lset(n), lsort(n), +lreverse(n), lsearch(n), lseq(n), lset(n), lsort(n), string(n) .SH KEYWORDS element, list, replace diff --git a/doc/lindex.n b/doc/lindex.n index 0ba30a4..d4d845d 100644 --- a/doc/lindex.n +++ b/doc/lindex.n @@ -117,7 +117,7 @@ set idx 3 .SH "SEE ALSO" list(n), lappend(n), lassign(n), ledit(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), -lreverse(n), lsearch(n), lset(n), lsort(n), +lreverse(n), lsearch(n), lseq(n), lset(n), lsort(n), string(n) .SH KEYWORDS element, index, list diff --git a/doc/linsert.n b/doc/linsert.n index 685b563..014f9cd 100644 --- a/doc/linsert.n +++ b/doc/linsert.n @@ -47,7 +47,7 @@ set newerList [\fBlinsert\fR [\fBlinsert\fR $oldList end-1 quick] 1 lazy] .SH "SEE ALSO" list(n), lappend(n), lassign(n), ledit(n), lindex(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), -lreverse(n), lsearch(n), lset(n), lsort(n), +lreverse(n), lsearch(n), lseq(n), lset(n), lsort(n), string(n) .SH KEYWORDS element, insert, list diff --git a/doc/list.n b/doc/list.n index 1792560..08a6fe7 100644 --- a/doc/list.n +++ b/doc/list.n @@ -48,7 +48,7 @@ while \fBconcat\fR with the same arguments will return .SH "SEE ALSO" lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), -lreverse(n), lsearch(n), lset(n), lsort(n) +lreverse(n), lsearch(n), lseq(n), lset(n), lsort(n) .SH KEYWORDS element, list, quoting '\"Local Variables: diff --git a/doc/llength.n b/doc/llength.n index 7a3e6de..574834f 100644 --- a/doc/llength.n +++ b/doc/llength.n @@ -51,7 +51,7 @@ An empty list is not necessarily an empty string: .SH "SEE ALSO" list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), -lreverse(n), lsearch(n), lset(n), lsort(n) +lreverse(n), lsearch(n), lseq(n), lset(n), lsort(n) .SH KEYWORDS element, list, length '\" Local Variables: diff --git a/doc/lmap.n b/doc/lmap.n index 29b1242..36a0c7c 100644 --- a/doc/lmap.n +++ b/doc/lmap.n @@ -80,7 +80,7 @@ set prefix [\fBlmap\fR x $values {expr { break(n), continue(n), for(n), foreach(n), while(n), list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), -lreverse(n), lsearch(n), lset(n), lsort(n) +lreverse(n), lsearch(n), lseq(n), lset(n), lsort(n) .SH KEYWORDS foreach, iteration, list, loop, map '\" Local Variables: diff --git a/doc/lpop.n b/doc/lpop.n index 0a156ee..2a464eb 100644 --- a/doc/lpop.n +++ b/doc/lpop.n @@ -88,7 +88,7 @@ The indicated value becomes the new value of \fIx\fR. .SH "SEE ALSO" list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), -lreverse(n), lsearch(n), lset(n), lsort(n), +lreverse(n), lsearch(n), lseq(n), lset(n), lsort(n), string(n) .SH KEYWORDS element, index, list, remove, pop, stack, queue diff --git a/doc/lrange.n b/doc/lrange.n index c0434bb..38c4abf 100644 --- a/doc/lrange.n +++ b/doc/lrange.n @@ -73,7 +73,7 @@ elements to .SH "SEE ALSO" list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lremove(n), lrepeat(n), lreplace(n), -lreverse(n), lsearch(n), lset(n), lsort(n), +lreverse(n), lsearch(n), lseq(n), lset(n), lsort(n), string(n) .SH KEYWORDS element, list, range, sublist diff --git a/doc/lremove.n b/doc/lremove.n index e71f607..8763ea6 100644 --- a/doc/lremove.n +++ b/doc/lremove.n @@ -48,7 +48,7 @@ a b d e .SH "SEE ALSO" list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lrepeat(n), lreplace(n), -lreverse(n), lsearch(n), lset(n), lsort(n) +lreverse(n), lsearch(n), lseq(n), lset(n), lsort(n) .SH KEYWORDS element, list, remove .\" Local variables: diff --git a/doc/lrepeat.n b/doc/lrepeat.n index de7ba54..cd672db 100644 --- a/doc/lrepeat.n +++ b/doc/lrepeat.n @@ -34,7 +34,7 @@ is identical to \fBlist element ...\fR. .SH "SEE ALSO" list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lreplace(n), -lreverse(n), lsearch(n), lset(n), lsort(n) +lreverse(n), lsearch(n), lseq(n), lset(n), lsort(n) .SH KEYWORDS element, index, list '\" Local Variables: diff --git a/doc/lreplace.n b/doc/lreplace.n index 6694ad7..47d33f9 100644 --- a/doc/lreplace.n +++ b/doc/lreplace.n @@ -97,7 +97,7 @@ a b c d e f g h i .SH "SEE ALSO" list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), -lreverse(n), lsearch(n), lset(n), lsort(n), +lreverse(n), lsearch(n), lseq(n), lset(n), lsort(n), string(n) .SH KEYWORDS element, list, replace diff --git a/doc/lreverse.n b/doc/lreverse.n index 0f0b6d6..bb0703d 100644 --- a/doc/lreverse.n +++ b/doc/lreverse.n @@ -27,7 +27,7 @@ input list, \fIlist\fR, except with the elements in the reverse order. .SH "SEE ALSO" list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), -lsearch(n), lset(n), lsort(n) +lsearch(n), lseq(n), lset(n), lsort(n) .SH KEYWORDS element, list, reverse '\" Local Variables: diff --git a/doc/lsearch.n b/doc/lsearch.n index 85b8609..dc6d1f7 100644 --- a/doc/lsearch.n +++ b/doc/lsearch.n @@ -231,7 +231,7 @@ The same thing for a flattened list: foreach(n), list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), -lreverse(n), lset(n), lsort(n), +lreverse(n), lseq(n), lset(n), lsort(n), string(n) .SH KEYWORDS binary search, linear search, diff --git a/doc/lseq.n b/doc/lseq.n index 5c7d03b..df8a8bc 100644 --- a/doc/lseq.n +++ b/doc/lseq.n @@ -81,8 +81,8 @@ must be numeric; a non-numeric string will result in an error. .\" .CE .SH "SEE ALSO" -foreach(n), list(n), lappend(n), lassign(n), lindex(n), linsert(n), llength(n), -lmap(n), lpop(n), lrange(n), lremove(n), lreplace(n), +foreach(n), list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), +llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lreplace(n), lreverse(n), lsearch(n), lset(n), lsort(n) .SH KEYWORDS element, index, list diff --git a/doc/lset.n b/doc/lset.n index 588a0a5..e2e1590 100644 --- a/doc/lset.n +++ b/doc/lset.n @@ -138,7 +138,7 @@ The indicated return value also becomes the new value of \fIx\fR. .SH "SEE ALSO" list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), -lreverse(n), lsearch(n), lsort(n) +lreverse(n), lsearch(n), lseq(n), lsort(n) string(n) .SH KEYWORDS element, index, list, replace, set diff --git a/doc/lsort.n b/doc/lsort.n index ddf9ed1..1695ea8 100644 --- a/doc/lsort.n +++ b/doc/lsort.n @@ -266,7 +266,7 @@ More complex sorting using a comparison function: .SH "SEE ALSO" list(n), lappend(n), lassign(n), ledit(n), lindex(n), linsert(n), llength(n), lmap(n), lpop(n), lrange(n), lremove(n), lrepeat(n), lreplace(n), -lreverse(n), lsearch(n), lset(n) +lreverse(n), lsearch(n), lseq(n), lset(n) .SH KEYWORDS element, list, order, sort '\" Local Variables: -- cgit v0.12