If found, a position is returned. If not found, the empty string is returned. I suppose, it would be better to return "-1", if not found.
Dear Tk community,
please allow me to inform you about a private communication with Jan
which enlighted me about recent Tk concepts.
----
P.S. by Harald:
I personally always avoid the mixing of data types due to shimmering.
So, a check like "if {$Index eq ""}" would transform a present number to
a string. This may be avoided by "if {$index == -1}". And a check "if {$Index < 0}" to test for the empty string is IMHO not at all transparent. But, as usual, I don't see the whole picture and think to small....
Le jeudi 7 avril 2022 à 11:46:25 UTC+2, Harald Oehlmann a écrit :
please allow me to inform you about a private communication with Jan...
which enlighted me about recent Tk concepts.
P.S. by Harald:I totally agree with you, I avoid shimmering in my code too, and I find mixing
I personally always avoid the mixing of data types due to shimmering.
So, a check like "if {$Index eq ""}" would transform a present number to
a string. This may be avoided by "if {$index == -1}". And a check "if
{$Index < 0}" to test for the empty string is IMHO not at all transparent. >> But, as usual, I don't see the whole picture and think to small....
result type of default Tcl commands a totally bad idea.
I wonder how the TIP 577 as been accepted, with such "Compatiblity" section. Also Jan already started to update Tk code (trunk and branch 8.6) do do the same with [lsearch]...
returning "" as a none found result is common when the result is a list. I'm not sure it is a good idea when an index is expected. "" is a valid index in some cases, but it does not necessarily imply nothing is selected. For example:
# a list for examples
set ll {1 2 3 a b c}
lsearch -all $ll k
#returns an empty list ""
#however
lsearch $ll k
#returns a valid index -1 (nothing found)
#under the current system
lindex $ll [lsearch $ll a]
#returns "a"
#and
lindex $ll [lsearch $ll k]
#returns "", a reasonable result.
#However under the proposed change it would return the complete list.
lindex $ll ""
#currently returns the whole list, which makes sense in the context of nested list indexes. But not as the resut of a search.
Dave B
Dear Tk community,
please allow me to inform you about a private communication with Jan
which enlighted me about recent Tk concepts.
I had asked, why the result of the functions of TIP621 resturn the empty string if not found and a character position if found.
At Fri, 08 Apr 22 14:55:01 GMT clt.to.davebr@dfgh.net wrote:...
# a list for examples
set ll {1 2 3 a b c}
lindex $ll [lsearch $ll k]
#returns "", a reasonable result.
#However under the proposed change it would return the complete list.
lindex $ll ""
So what would you expect
lindex $ll [lsearch -all $ll k]
to return???
Robert Heller <hel...@deepsoft.com> wrote:
At Fri, 08 Apr 22 14:55:01 GMT clt.to...@dfgh.net wrote:...
# a list for examples
set ll {1 2 3 a b c}
lindex $ll [lsearch $ll k]
#returns "", a reasonable result.
#However under the proposed change it would return the complete list.
lindex $ll ""
So what would you expectNothing useful, of course.
lindex $ll [lsearch -all $ll k]
to return???
And it was not clt.to.davebr's example.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 493 |
Nodes: | 16 (2 / 14) |
Uptime: | 181:11:07 |
Calls: | 9,705 |
Files: | 13,737 |
Messages: | 6,179,425 |