Skip to content
Tcl Source Code History Of Ticket edebb6a4
Login

History Of Ticket edebb6a4

Artifacts Associated With Ticket edebb6a4

  1. Ticket change [c66d03230b] (rid 234899) by pooryorick on 2024-11-08 11:45:39:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-wiki"
    4. 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.
      
    5. is_private initialized to: "0"
    6. login: "pooryorick"
    7. priority initialized to: "5 Medium"
    8. private_contact initialized to: "5d4b6538b2536427c4ee4dd0ec7495de74567d31"
    9. resolution initialized to: "None"
    10. severity initialized to: "Minor"
    11. status initialized to: "Open"
    12. submitter initialized to: "pooryorick"
    13. subsystem initialized to: "- New Builtin Commands"
    14. title initialized to: "lsearch -index requires nested items to exist"
    15. type initialized to: "Bug"
  2. Ticket change [da1232507b] (rid 234920) by juliannoble2 on 2024-11-09 18:26:19:

    1. 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?
      
    2. login: "juliannoble2"
    3. mimetype: "text/plain"
  3. Ticket change [9ec2f3d9f1] (rid 234929) by oehhar on 2024-11-10 14:58:41:

    1. 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
      
    2. login: "oehhar"
    3. mimetype: "text/x-fossil-wiki"
    4. username: "oehhar"
  4. Ticket change [64f2e47259] (rid 234930) by griffin on 2024-11-10 16:05:02:

    1. 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.
      
    2. login: "griffin"
    3. mimetype: "text/x-markdown"
  5. Ticket change [fea7fbff9f] (rid 234939) by pooryorick on 2024-11-10 22:16:34:

    1. 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.
      
    2. login: "pooryorick"
    3. mimetype: "text/x-fossil-wiki"