• lsearch realization

    From meshparts@alexandru.dadalau@meshparts.de to comp.lang.tcl on Wed Sep 17 16:19:56 2025
    From Newsgroup: comp.lang.tcl


    I just realized, that

    lsearch -real -index 0 {0 1.0} 1.00

    does not find the 1.0 element in the given list!

    Same for:

    lsearch -real -index 0 {0 1.0} 1

    Why is that???

    Since "expr 1.0==1.00" and "expr 1.0==1" return true, I realy wonder...

    Any explanation for this behavior?


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From saito@saitology9@gmail.com to comp.lang.tcl on Wed Sep 17 10:49:26 2025
    From Newsgroup: comp.lang.tcl

    On 9/17/2025 10:19 AM, meshparts wrote:

    I just realized, that

    lsearch -real -index 0 {0 1.0} 1.00

    does not find the 1.0 element in the given list!

    Same for:

    lsearch -real -index 0 {0 1.0} 1

    Why is that???

    Since "expr 1.0==1.00" and "expr 1.0==1" return true, I realy wonder...

    Any explanation for this behavior?



    Interesting. Tcl 8.6 gives the expected results, or so it seems at first:

    % lsearch -real -index 0 {0 1.0} 1.0
    1

    Bu then look at these:

    % lsearch -real -index 0 {0 1.0} 1.00
    -1

    % lsearch -real -index 0 {0 1.0} 1.000
    -1


    Convert your pattern to a real number doesn't seem to really help either:

    % lsearch -real -index 0 {0 1.0} [expr 1.000]
    1


    % lsearch -real -index 0 {0 1.00} [expr 1.000]
    -1







    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Schelte@nospam@wanadoo.nl to comp.lang.tcl on Wed Sep 17 17:26:33 2025
    From Newsgroup: comp.lang.tcl

    On 17/09/2025 16:19, meshparts wrote:
    lsearch -real -index 0 {0 1.0} 1.00

    does not find the 1.0 element in the given list!

    [snip]>
    Any explanation for this behavior?

    The matching style for lsearch defaults to -glob. The -real option is
    only meaningful when used with the -exact option. And then it works as expected:

    % lsearch -exact -real {0 1.0} 1.00
    1
    % lsearch -exact -real {0 1.0} 1
    1

    I concede that it would make sense for the -real option (and a few other options) to imply -exact.


    Schelte

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From meshparts@alexandru.dadalau@meshparts.de to comp.lang.tcl on Wed Sep 17 18:38:15 2025
    From Newsgroup: comp.lang.tcl

    Am 17.09.2025 um 17:26 schrieb Schelte:
    On 17/09/2025 16:19, meshparts wrote:
    lsearch -real -index 0 {0 1.0} 1.00

    does not find the 1.0 element in the given list!

    [snip]>
    Any explanation for this behavior?

    The matching style for lsearch defaults to -glob. The -real option is
    only meaningful when used with the -exact option. And then it works as expected:

    % lsearch -exact -real {0 1.0} 1.00
    1
    % lsearch -exact -real {0 1.0} 1
    1

    I concede that it would make sense for the -real option (and a few other options) to imply -exact.


    Schelte

    Oh, right! Thanks!
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From saito@saitology9@gmail.com to comp.lang.tcl on Wed Sep 17 14:47:34 2025
    From Newsgroup: comp.lang.tcl

    On 9/17/2025 11:26 AM, Schelte wrote:

    The matching style for lsearch defaults to -glob. The -real option is
    only meaningful when used with the -exact option. And then it works as expected:


    Nice!



    --- Synchronet 3.21a-Linux NewsLink 1.2