diff options
author | Danyil Bohdan <danyil.bohdan@gmail.com> | 2014-07-25 12:52:28 +0300 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2014-07-26 13:43:08 +1000 |
commit | a07760e95c68569b635ecc97465175d9a306ff37 (patch) | |
tree | 64c9a11283b68852aaf3a204df5dc8579ec910e5 | |
parent | eff89bbd45fce0af30d819718076a3d0890f6a5a (diff) | |
download | jimtcl-a07760e95c68569b635ecc97465175d9a306ff37.zip jimtcl-a07760e95c68569b635ecc97465175d9a306ff37.tar.gz jimtcl-a07760e95c68569b635ecc97465175d9a306ff37.tar.bz2 |
jim.c: make lindex work as identity function.
-rw-r--r-- | jim.c | 4 | ||||
-rw-r--r-- | jim_tcl.txt | 10 | ||||
-rw-r--r-- | tests/jim.test | 10 |
3 files changed, 17 insertions, 7 deletions
@@ -12229,8 +12229,8 @@ static int Jim_LindexCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *a int i; int idx; - if (argc < 3) { - Jim_WrongNumArgs(interp, 1, argv, "list index ?...?"); + if (argc < 2) { + Jim_WrongNumArgs(interp, 1, argv, "list ?index ...?"); return JIM_ERR; } objPtr = argv[1]; diff --git a/jim_tcl.txt b/jim_tcl.txt index 289efbf..255d12b 100644 --- a/jim_tcl.txt +++ b/jim_tcl.txt @@ -2881,7 +2881,7 @@ affect the loop count. lindex ~~~~~~ -+*lindex* 'list index'+ ++*lindex* 'list ?index ...?'+ Treats +'list'+ as a Tcl list and returns element +'index'+ from it (0 refers to the first element of the list). @@ -2891,8 +2891,14 @@ In extracting the element, +'lindex'+ observes the same rules concerning braces and quotes and backslashes as the Tcl command interpreter; however, variable substitution and command substitution do not occur. +If no index values are given, simply returns +'list'+ + If +'index'+ is negative or greater than or equal to the number of elements -in +'value'+, then an empty string is returned. +in +'list'+, then an empty string is returned. + +If additional index arguments are supplied, then each argument is +used in turn to select an element from the previous indexing +operation, allowing the script to select elements from sublists. linsert ~~~~~~~ diff --git a/tests/jim.test b/tests/jim.test index c1ab8e7..c83a047 100644 --- a/tests/jim.test +++ b/tests/jim.test @@ -1539,9 +1539,9 @@ set minus - # Tests of Tcl_LindexObjCmd, NOT COMPILED -#test lindex-1.1 {wrong # args} { -# list [catch {eval $lindex} result] $result -#} "1 {wrong # args: should be \"lindex list ?index...?\"}" +test lindex-1.1 {wrong # args} { + list [catch {eval $lindex} result] $result +} "1 {wrong # args: should be \"lindex list ?index ...?\"}" # Indices that are lists or convertible to lists @@ -1834,6 +1834,10 @@ test lindex-16.3 {data reuse} { set result } {} +test lindex-17.1 {no index} { + lindex {a b c} +} {a b c} + catch { unset lindex} catch { unset minus } |