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

    From Harald Oehlmann@21:1/5 to All on Fri May 6 12:27:56 2022
    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]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ashok@21:1/5 to Harald Oehlmann on Fri May 6 17:20:07 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arjen Markus@21:1/5 to Ashok on Fri May 6 07:13:01 2022
    On Friday, May 6, 2022 at 1:50:12 PM UTC+2, Ashok wrote:
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arjen Markus@21:1/5 to Ashok on Fri May 6 07:16:29 2022
    On Friday, May 6, 2022 at 1:50:12 PM UTC+2, Ashok wrote:
    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

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From heinrichmartin@21:1/5 to Harald Oehlmann on Sat May 7 14:04:56 2022
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)