Menu

#3319 lsearch -start inconsistent return

obsolete: 8.4.12
closed-fixed
5
2005-12-09
2005-12-06
Anonymous
No

The return for
lsearch -start X $list Value
is different when X >= end
and Value is the last or non-last list element.

set l {a b c d a b c d}

lsearch -start 5 $l d
returns 7, as expected
lsearch -start 999 $l d
returns 7
lsearch -start 999 $l c
returns -1

Discussion

  • Donal K. Fellows

    • assigned_to: dkf --> dgp
     
  • Donal K. Fellows

    Logged In: YES
    user_id=79902

    Any opinion on whether to fix this for 8.4 or 8.5? Or should
    it just be closed as "meant to work that way"?

    Please assign back to me with the comment.

     
  • Don Porter

    Don Porter - 2005-12-08
    • assigned_to: dgp --> dkf
     
  • Don Porter

    Don Porter - 2005-12-08

    Logged In: YES
    user_id=80530

    I would expect that

    lsearch -start $x $l $i

    with $x an integer would
    either return -1 (not found)
    or would return an integer
    greater than or equal to $x .

    [lsearch -start 999 $l d] => 7

    goes against my expectations,
    and suggests the search did
    not start at index 999 as
    instructed, but started at
    index 7 instead.

    This looks like a bug to me,
    and as such ought to be fixed
    for 8.4.13.

    I'm willing to be talked
    out of that if this "feature"
    enables some particularly
    elegant coding of some particularly
    useful algorithm. In that case,
    I'd want really good documentation.

     
  • Donal K. Fellows

    • status: open --> closed-fixed
     
  • Donal K. Fellows

    Logged In: YES
    user_id=79902

    Fixed in HEAD and 8.4 branch (looking off the end of a list
    always finds nothing)