Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why does tcl::mathop::|| not exist ?

77 views
Skip to first unread message

Harald Oehlmann

unread,
May 6, 2022, 6:28:00 AM5/6/22
to
Dear TCL team,

I love the tcl::mathop and tcl::mathfunc commands to just use one
command and to avoid expr. In addition, list arguments must not be
transformed to comma separated values.

I wanted to find, if a list of bools (0/1 values) has one 1

set list {0 0 1 0}

So, I tried:

tcl::mathop::|| 0 {*}$list

Unfortunately, "tcl::mathop::||" does not exist. Probably, this is due
to the fact, that it is handled internally in expr.

IMHO, it would be great, if it would exist, even if not used in expr.

Thank you all,
Harald

Epilog: other solutions for the issue

tcl::mathfunc::max 0 {*}$list

Which does not support bools in any form. This is ok in my use-case.

Or:
-1 != [lsearch -integer $list 1]

Ashok

unread,
May 6, 2022, 7:50:12 AM5/6/22
to
On 5/6/2022 3:57 PM, Harald Oehlmann wrote:
> Dear TCL team,
> Unfortunately, "tcl::mathop::||" does not exist. Probably, this is due
> to the fact, that it is handled internally in expr.
>
> IMHO, it would be great, if it would exist, even if not used in expr.
>
> Thank you all,
> Harald
>

My *guess* is that it's because the expected semantics of || in almost
all languages are short-circuit operation so later arguments do not get
evaluated.

For example

(bin) 4 % expr {1 || $undefined}
1

It is not possible to implement this behavior with the command argument
Tcl syntax.

/Ashok

Arjen Markus

unread,
May 6, 2022, 10:13:07 AM5/6/22
to

Arjen Markus

unread,
May 6, 2022, 10:16:32 AM5/6/22
to
On Friday, May 6, 2022 at 1:50:12 PM UTC+2, Ashok wrote:
You can define them as functions instead, but the symbols themselves are binary operations, so two sides are required. But the names || and &&, as its pendant, interfer with the parsing of the expression. (Aside: In Fortran you have the intrinsic functions all and any for this)

Regards,

Arjen

heinrichmartin

unread,
May 7, 2022, 5:04:58 PM5/7/22
to
On Friday, May 6, 2022 at 12:28:00 PM UTC+2, Harald Oehlmann wrote:
> I wanted to find, if a list of bools (0/1 values) has one 1
>
> set list {0 0 1 0}
>
> ...
>
> Epilog: other solutions for the issue
>
> tcl::mathfunc::max 0 {*}$list
>
> Which does not support bools in any form. This is ok in my use-case.
>
> Or:
> -1 != [lsearch -integer $list 1]

Whether or not -integer is an advantage in your case depends on how the list is created. set list {0 0 1 0} holds strings.

Also, if lsearch is correct for your data, then operators "in"/"ni" will most likely be, too. So are bit-wise operators.

And for the fun of it: while max requires that 0 in case of empty lists, + does not, i.e. if {[::tcl::mathop::+ {*}$list]} works.
0 new messages