From a07760e95c68569b635ecc97465175d9a306ff37 Mon Sep 17 00:00:00 2001 From: Danyil Bohdan Date: Fri, 25 Jul 2014 12:52:28 +0300 Subject: jim.c: make lindex work as identity function. --- jim.c | 4 ++-- jim_tcl.txt | 10 ++++++++-- tests/jim.test | 10 +++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/jim.c b/jim.c index 93eeff3..76a192e 100644 --- a/jim.c +++ b/jim.c @@ -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 } -- cgit v1.1