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

Why [tcl::mathfunc::min 1 2] but [expr min(1,2)] with commas?

73 views
Skip to first unread message

Busirane

unread,
Sep 22, 2017, 10:14:50 AM9/22/17
to
I use min and max infrequently enough that, when I do, I always trip over the differing syntax of the expr and mathfunc versions. Why does [expr min()] want commas? Especially since it *allows* whitespace, as long as there's a comma too. It's almost like [expr min()] expects a single string argument, but that's not how it's documented, at least in 8.5.13.

Gerald Lester

unread,
Sep 22, 2017, 11:35:42 AM9/22/17
to
On 09/22/2017 09:14 AM, Busirane wrote:
> I use min and max infrequently enough that, when I do, I always trip over the differing syntax of the expr and mathfunc versions. Why does [expr min()] want commas? Especially since it *allows* whitespace, as long as there's a comma too. It's almost like [expr min()] expects a single string argument, but that's not how it's documented, at least in 8.5.13.
>

Because [expr] has its own mini-language (as do regular expressions) and
the [expr[ mini-language is an infix language and not a prefix one.

In short, it is what it is for historical reasons.

--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+----------------------------------------------------------------------+

Georgios Petasis

unread,
Sep 22, 2017, 12:21:15 PM9/22/17
to
Στις 22/9/2017 18:35, ο Gerald Lester έγραψε:
> On 09/22/2017 09:14 AM, Busirane wrote:
>> I use min and max infrequently enough that, when I do, I always trip
>> over the differing syntax of the expr and mathfunc versions. Why does
>> [expr min()] want commas? Especially since it *allows* whitespace, as
>> long as there's a comma too. It's almost like [expr min()] expects a
>> single string argument, but that's not how it's documented, at least
>> in 8.5.13.
>>
>
> Because [expr] has its own mini-language (as do regular expressions) and
> the [expr[ mini-language is an infix language and not a prefix one.
>
> In short, it is what it is for historical reasons.
>

Also, the functions in tcl::mathfunc::* are the underline implementation
of expr's functions. Adding new functions in the tcl::mathfunc
namespace, will make these functions available through expr.

For example:

proc tcl::mathfunc::test_func {a} {puts $a; incr a}
expr test_func(8)

8
9

George

Rich

unread,
Sep 22, 2017, 4:27:00 PM9/22/17
to
Likely because traditional mathematical functional notation uses commas
to separate function arguments. So 'expr' functional notation uses
commas at the separator to maintain a semblance of familarity in using
the functions.

The Tcl proc's in the mathfunc namespace are Tcl proc's, so they play
by Tcl proc argument rules, not mathematical functional notation rules.

Busirane

unread,
Sep 26, 2017, 9:04:56 AM9/26/17
to
On Friday, September 22, 2017 at 11:35:42 AM UTC-4, Gerald Lester wrote:
> it is what it is for historical reasons.

That's actually the answer I expected when I asked the question. Thanks, Gerald.
0 new messages