Artifacts Associated With Ticket edebb6a4
Ticket change [c66d03230b] (rid 234899) by pooryorick on 2024-11-08 11:45:39:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
The following command, <code><verbatim> lsearch -index 0 {{} one two three} one </verbatim></code> Fails with the error <code><verbatim> element 0 missing from sublist "" </verbatim></code> lsearch would be more useful if the meaning of "-index" was just "match against each value that has such an item", without the additional "each value must have such an item" constraint. A script that uses lsearch is usually more interested in determing which items match, not ensuring that all items meet some criteria. - is_private initialized to: "0"
- login: "pooryorick"
- priority initialized to: "5 Medium"
- private_contact initialized to: "5d4b6538b2536427c4ee4dd0ec7495de74567d31"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "pooryorick"
- subsystem initialized to: "- New Builtin Commands"
- title initialized to: "lsearch -index requires nested items to exist"
- type initialized to: "Bug"
Ticket change [da1232507b] (rid 234920) by juliannoble2 on 2024-11-09 18:26:19:
- icomment:
For working with flat lists - this can sometimes be a bit annoying/unintuitive. % lsearch -stride 3 -index {0 0} -subindices -all -inline {f1 a1 a2 f2 b1 ""} * f1 f2 % lsearch -stride 3 -index {1 0} -subindices -all -inline {f1 a1 a2 f2 b1 ""} * a1 b1 % lsearch -stride 3 -index {2 0} -subindices -all -inline {f1 a1 a2 f2 b1 ""} * element 0 missing from sublist "" Usually I'd just reconfigure the datastructure to use lists of lists - but there are some things for which a flat list is more suited. e.g in console work; for outputting a list of words in columns - where the number of columns might change based on available display width. proc filler_count {listlen numcolumns} { expr {($numcolumns - ($listlen % $numcolumns)) % $numcolumns} } proc col {list numcolumns colindex {blank NULL}} { lsearch -stride $numcolumns -index [list $colindex 0] -subindices -all -inline [list {*}$list {*}[lrepeat [filler_count [llength $list] $numcolumns] $blank]] * } #... remainder of block display code omitted. %col {a bunch of words to put in a grid etc} 3 0 ;#retrieve the first column of the words arranged into a total of 3 columns so you can determine the width required for the column. a words in etc This will fail if the wordlist contains an empty string, or if you set the 'blank' argument to empty string. It can be worked around by using {""} or some other character for empty-string words in the list and for the 'blank' argument - or of course just by using something other than the lsearch -stride mechanism to build the lists. It does seem something of a pity this doesn't work as might first be expected - but I guess the trade-off might be due to maintaining the ability to differentiate empty string values vs missing items, or in aiding error detection in list structures? - login: "juliannoble2"
- mimetype: "text/plain"
- icomment:
Ticket change [9ec2f3d9f1] (rid 234929) by oehhar on 2024-11-10 14:58:41:
- icomment:
IMHO the requirement that a not existing element can never be found would be a good idea. It is more tcl-like than erroring out. Any other comments on this ? Thanks, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [64f2e47259] (rid 234930) by griffin on 2024-11-10 16:05:02:
- icomment:
Is an empty string a list? The answer is yes. Therefore, this scenario should not be an error. The value of "lindex {} 0" is {}, which is a valid list. - login: "griffin"
- mimetype: "text/x-markdown"
- icomment:
Ticket change [fea7fbff9f] (rid 234939) by pooryorick on 2024-11-10 22:16:34:
- icomment:
It's not the same case as <code>lindex {} 0</code> being the empty string. Consider this command: <code><verbatim> lsearch -index 0 {one two three {}} {} </verbatim></code> The result should be -1, not 3. The absence of an item at index zero should not compare equal to the empty string. - login: "pooryorick"
- mimetype: "text/x-fossil-wiki"
- icomment: