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.
Here is the question and the answers by Jan.
Enjoy,
Harald
Op wo 6 apr. 2022 om 19:45 schreef Harald Oehlmann:
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.
Well, this is 100% as intended. See:
<
https://core.tcl-lang.org/tips/doc/trunk/tip/577.md>
I always found it strange in Tcl and Tk that "-1" is used as
"not-found". In my opinion, "" would be more logical. I'm
preparing
<
https://core.tcl-lang.org/tips/doc/trunk/tip/615.md>
to do the same in Tcl as in Tk. If we accept more than only
integers as index value, why not "" as well?
I realize that it has a lot of impact in Tcl, if we change all
functions returning "-1" to return "" instead. It means that
all scripts cannot use this any more:
if {[some command] == -1} {
}
they need to change that to:
if {[some command] < 0} {
}
(since "" is smaller than 0 too, this works with both "" and -1)
Therefore, this can only be done in Tcl 9.0, and possibly
not for all commands yet.
Since Tk is consistent now (when building with Tcl 9.0,
all search-functions return "", not -1) better let new
functions behave like this from the start ....
Hope this helps,
Jan Nijtmans
----
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....
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)