Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 9e690747502789f1ac835581ffbbc1c0371ab3ea3625d72cb2593066d60c67d4
Ticket: 5a1aaa201da8bd4ba2b37348c5247c98d192321e
lsearch -stride with -subindices and -inline -all gives unexpected result
User & Date: juliannoble2 on 2024-11-11 12:07:48
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-plain"
  4. comment changed to:
      %lsearch -stride 3 -index 0 -subindices -inline {a1 b1 c1 a2 b2 c2} a*
      a1
    
      %lsearch -stride 3 -index 0 -subindices -inline -all {a1 b1 c1 a2 b2 c2} a*
      a1 b1 c1 a2 b2 c2
    
    If we omit the -inline flag the indices are as expected
    
      %lsearch -stride 3 -index 0 -subindices -all {a1 b1 cc1 a2 b2 c2} a*
      0 3
    
    This second result is unexpected. (and gives the same result as with -subindices omitted)
    
    Tip 351 example 5 indicates some level of consistency with the nested equivalent should be expected.
    
      %lsearch -index 0 -subindices -inline {{a1 b1 c1} {a2 b2 c2}} a*
      a1
    
      %lsearch -index 0 -subindices -inline -all {{a1 b1 c1} {a2 b2 c2}} a*
      a1 a2
    
    The second result here is what I would have expected for the stridden version.
    
    This makes certain operations with flattened lists harder to do. It can be worked around by using combinations of lseq, lmap etc instead of lsearch - but nothing seems as performant as a single lsearch -stride operation.
    
    See my example code in bug https://core.tcl-lang.org/tcl/tktview/edebb6a4 regarding empty strings.
    In that case - I had to artificially use an extra level of indices to extract what's required - and then ran headlong into that issue regarding empty string members (and also wrong results for members containing spaces)
    
    One workaround I've used is to list protect every member of my flattened list - and then use the double index such as -index {0 0}
    The additional prep overhead of doing something like: lmap v $list {list v} on a large list wipes out any performance gains from using lsearch -stride.
    
  5. is_private changed to: "0"
  6. login: "juliannoble2"
  7. priority changed to: "5 Medium"
  8. private_contact changed to: "957fdfcd8744611e3fe1f4896c7538b1d9bf47b2"
  9. resolution changed to: "None"
  10. severity changed to: "Important"
  11. status changed to: "Open"
  12. submitter changed to: "juliannoble2"
  13. subsystem changed to: "17. Commands I-L"
  14. title changed to:
    lsearch -stride with -subindices and -inline -all gives unexpected result
    
  15. type changed to: "Bug"