Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

[It is] best to confuse only one issue at a time. -- K&R


programming / comp.lang.tcl / Re: Why does tcl::mathop::|| not exist ?

SubjectAuthor
* Why does tcl::mathop::|| not exist ?Harald Oehlmann
+* Re: Why does tcl::mathop::|| not exist ?Ashok
|+- Re: Why does tcl::mathop::|| not exist ?Arjen Markus
|`- Re: Why does tcl::mathop::|| not exist ?Arjen Markus
`- Re: Why does tcl::mathop::|| not exist ?heinrichmartin

1
Subject: Why does tcl::mathop::|| not exist ?
From: Harald Oehlmann
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 6 May 2022 10:27 UTC
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: wortka...@yahoo.de (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Why does tcl::mathop::|| not exist ?
Date: Fri, 6 May 2022 12:27:56 +0200
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <t52t7c$k5v$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 6 May 2022 10:27:56 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="775d66a425fd6bad22024012c585b06b";
logging-data="20671"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/0mJ6AfI88+5Rff9zoK3XM"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.9.0
Cancel-Lock: sha1:Iq89s/37ZsBU1QvXLbrf0zAl8mU=
Content-Language: en-GB
View all headers
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]



Subject: Re: Why does tcl::mathop::|| not exist ?
From: Ashok
Newsgroups: comp.lang.tcl
Organization: A noiseless patient Spider
Date: Fri, 6 May 2022 11:50 UTC
References: 1
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: palm...@yahoo.com (Ashok)
Newsgroups: comp.lang.tcl
Subject: Re: Why does tcl::mathop::|| not exist ?
Date: Fri, 6 May 2022 17:20:07 +0530
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <t5321g$nso$1@dont-email.me>
References: <t52t7c$k5v$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 6 May 2022 11:50:08 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ae06a55535ea5178d92f0f46a1eef61a";
logging-data="24472"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/rMOhX8vUEXd2xZ7b52uj+"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Cancel-Lock: sha1:K3sWhK78H5p6tB8vAeQVAc/KDe8=
In-Reply-To: <t52t7c$k5v$1@dont-email.me>
Content-Language: en-US
View all headers
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



Subject: Re: Why does tcl::mathop::|| not exist ?
From: Arjen Markus
Newsgroups: comp.lang.tcl
Date: Fri, 6 May 2022 14:13 UTC
References: 1 2
X-Received: by 2002:a37:68ca:0:b0:6a0:4bd:6098 with SMTP id d193-20020a3768ca000000b006a004bd6098mr2445934qkc.605.1651846382241;
Fri, 06 May 2022 07:13:02 -0700 (PDT)
X-Received: by 2002:a05:6870:c5a5:b0:da:ab36:48dd with SMTP id
ba37-20020a056870c5a500b000daab3648ddmr1352968oab.150.1651846381910; Fri, 06
May 2022 07:13:01 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 6 May 2022 07:13:01 -0700 (PDT)
In-Reply-To: <t5321g$nso$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=62.194.62.207; posting-account=A91wAAoAAADgBUxBX6QqsrSD26GLhVp8
NNTP-Posting-Host: 62.194.62.207
References: <t52t7c$k5v$1@dont-email.me> <t5321g$nso$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7b3250a5-e7ff-4a0c-975d-d2b01bd55166n@googlegroups.com>
Subject: Re: Why does tcl::mathop::|| not exist ?
From: arjen.ma...@gmail.com (Arjen Markus)
Injection-Date: Fri, 06 May 2022 14:13:02 +0000
Content-Type: text/plain; charset="UTF-8"
View all headers
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


Subject: Re: Why does tcl::mathop::|| not exist ?
From: Arjen Markus
Newsgroups: comp.lang.tcl
Date: Fri, 6 May 2022 14:16 UTC
References: 1 2
X-Received: by 2002:a05:620a:2886:b0:699:bab7:ae78 with SMTP id j6-20020a05620a288600b00699bab7ae78mr2454955qkp.618.1651846590062;
Fri, 06 May 2022 07:16:30 -0700 (PDT)
X-Received: by 2002:a05:6870:1781:b0:e2:f30d:3a6c with SMTP id
r1-20020a056870178100b000e2f30d3a6cmr1402580oae.142.1651846589606; Fri, 06
May 2022 07:16:29 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Fri, 6 May 2022 07:16:29 -0700 (PDT)
In-Reply-To: <t5321g$nso$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=62.194.62.207; posting-account=A91wAAoAAADgBUxBX6QqsrSD26GLhVp8
NNTP-Posting-Host: 62.194.62.207
References: <t52t7c$k5v$1@dont-email.me> <t5321g$nso$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <dd8764be-119c-45f9-a6cb-43fc5411d44an@googlegroups.com>
Subject: Re: Why does tcl::mathop::|| not exist ?
From: arjen.ma...@gmail.com (Arjen Markus)
Injection-Date: Fri, 06 May 2022 14:16:30 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
View all headers
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


Subject: Re: Why does tcl::mathop::|| not exist ?
From: heinrichmartin
Newsgroups: comp.lang.tcl
Date: Sat, 7 May 2022 21:04 UTC
References: 1
X-Received: by 2002:a05:622a:40e:b0:2f3:bad4:ae29 with SMTP id n14-20020a05622a040e00b002f3bad4ae29mr8672162qtx.557.1651957496970;
Sat, 07 May 2022 14:04:56 -0700 (PDT)
X-Received: by 2002:a05:6830:33cf:b0:5af:4018:fc2a with SMTP id
q15-20020a05683033cf00b005af4018fc2amr3243162ott.161.1651957496754; Sat, 07
May 2022 14:04:56 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sat, 7 May 2022 14:04:56 -0700 (PDT)
In-Reply-To: <t52t7c$k5v$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=213.225.34.69; posting-account=Od2xOAoAAACEyRX3Iu5rYt4oevuoeYUG
NNTP-Posting-Host: 213.225.34.69
References: <t52t7c$k5v$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <85f534b3-1ba6-465c-af00-efb42b026866n@googlegroups.com>
Subject: Re: Why does tcl::mathop::|| not exist ?
From: martin.h...@frequentis.com (heinrichmartin)
Injection-Date: Sat, 07 May 2022 21:04:56 +0000
Content-Type: text/plain; charset="UTF-8"
View all headers
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.


1
rocksolid light 0.7.2
clearneti2ptor