Tcl 8.5: in & ni

(Printer friendly version)

Once upon a time (Tcl 7.x; probably earlier too?) the best way to test for string equality in Tcl was:

if {[string compare $x $y] == 0} ...

Beginning with Tcl 8.1.1 the preferred way became:

if {[string equal $x $y]} ...

Beginning with Tcl 8.4 and the introduction of the eq and ne operators testing for string equality became much more concise:

if {$x eq $y} ...

Much more readable, concise, and less to type. In Tcl 8.5 we get a simillar improvement for testing whether a particular item is a member (or not) of a list:

if {$x in $y} ...

Which IMHO is a huge improvement over the former idiom:

if {[lsearch -exact $y $x] != -1} ...

Naturally ni is to ne as in is to eq. And to top it all off, ni is fun to say too.

—Michael A. Cleverly


sara: [ mail | www | link ]

I read a article under the same title some time ago, but this articles quality is much, much better. How you do this..

Sun, 15 Jan 2023, 06:51

john elia: [ mail | www | link ]
Very useful post. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. Really its great article. Keep it up.%A0 Best Niagara Tour

Sat, 25 Mar 2023, 05:07

Leave a comment

Email: (optional)
URL: (optional)

Your comment: