On Wednesday, July 20, 2022 at 10:52:03 AM UTC+2, aotto1 wrote:
As you see that you have *TWO* *expr* first in the *mathfunc* and than
after in the *if*.
I am not sure whether I understand your concerns. Have you tested your claim?
expect:~$ proc ::tcl::mathfunc::hasFlag {val} {expr {-1 != [lsearch {a b c} $val]}}
expect:~$ expr {hasFlag("a")}
1
expect:~$ expr {hasFlag("d")}
0
expect:~$ proc ::tcl::mathfunc::hasFlag {val} {expr {$val in {a b c}}}
Both work for me.
Maybe your code at some point was: expr [lsearch $::flags $val] != -1 ;# i.e. without braces
expect:~$ proc ::tcl::mathfunc::hasFlag {val} {expr $val in {a b c}} ;# wrong! expect:~$ expr {hasFlag("a")}
invalid bareword "a"
in expression "a in a b c";
should be "$a" or "{a}" or "a(...)" or ...
while evaluating {expr {hasFlag("a")}}
On Wednesday, July 20, 2022 at 11:51:03 AM UTC+2, Ralf Fassel wrote:
In TCL 8.5ff this is
expr {$val in $::flags}
for the exact search (not glob or regexp).
And for strings only (which is the case in Otto's example), because in/ni create string representations for all list elements (up to the first match). [lsearch -integer] might still be the better choice when microseconds count ;-)
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)