two...@gmail.com <
two...@gmail.com> wrote:
> On Monday, November 5, 2018 at 8:39:14 AM UTC-8, Andreas Leitgeb wrote:
>> Such-tagged array-elements or even blank names could also make nice
>> arguments for e.g. some "incr" imported into tcl::mathfunc.
First of all, my comment was *not* about adding incr or any other
specific operator to expr. It is already possible to import commands/
procedures into tcl::mathfunc (or create them there), and then call
them from within an expression.
E.g. string length can be imported(*) as tcl::mathfunc::slen
and then used like [expr {(slen($str)+1)/2}] and it is
also possible to import commands that take a var name as an
argument, and incr is just one example of such a function.
Assuming that one has imported incr into tcl::mathfunc, then the
following is already legal syntax: [expr {incr("varname",42)}]
Similarly, one can also already now apply it on an array-element:
[expr {incr("arr($key)",42}]
It is also already possible to import the "set" command, and have
assignments like [expr {set("x",42)}]
Nothing new so far.
But when the discussion arose to add some assignment operator to expr,
(and iirc preferrence was for ":=" to avoid repeating C's mistake there)
they wanted a syntax that was "less ugly" than the one already possible -
so, under all circumstances anything than having the variable name bare
of any quoting would be worthy on left side of such an operator. Well,
quoted strings would still be allowed as well, but unless one could have
a bare varname or a bare array-element on left side of :=, then majority
of TCT would rather not have assignment, than require quoting; but
bare array-elements just would make expr syntax ambiguous.
While I agree that expr {"foo($key)" := ...} would indeed be pretty
strange to look at, I seemed to be alone in the world to consider
expr {'foo($key) := ...} an acceptable compromise.
> When I moved to using modula-2 instead of C, I never missed these
> operators.
Well, I did, and I was soo glad when that one course using modula-2
was finished and I would no longer have to talk to the compiler like
to a baby - I was used to ":=" already from Pascal, but not having a
polymorphic output procedure was awkward. I can see your point, but
it's really just a matter of personal preference.
> I would hope that the Tcl community would not wish to add these
> operators to the language ...
That was certainly not my point to suggest.