On 17/10/2025 23:23, et99 wrote:...
I've implemented a working prototype of TIP 672 - the $(expression)
syntax for Tcl.
One biggy: It's another irregularity making programming, which is
difficult, even more so. It doesn't take long for them to compose
together into development gridlock.
Tristan Wibberley <tristan.wibberley+netnews2@alumni.manchester.ac.uk> posted:
On 17/10/2025 23:23, et99 wrote:...
I've implemented a working prototype of TIP 672 - the $(expression)
syntax for Tcl.
One biggy: It's another irregularity making programming, which is
difficult, even more so. It doesn't take long for them to compose
together into development gridlock.
Hi Tristan, AIUI Eric (et99) has pretty much given up on his TIP 672
proposal now. Recently he has been quite supportive towards my alternative which is TIP 676 - https://core.tcl-lang.org/tips/doc/trunk/tip/676.md .
TIP 676 just proposes a command called `=` which would allow the examples Eric gave to be written as:
set result [= a + b * c]
puts "Total: [= sum+tax]"
This would not replace `expr`, it's just an alternative compact form for numerical/logical calculations, with no impact on the basic Tcl parsing
rules or the rest of the language.
So I'm wondering if you would consider this "NotRubbish" or not?
{=}{ ... } also seems NotRubbish to me on the same "regularity" factor I
was considering for rejecting the previously posted idea,
I've looked again at the two competing proposals for an alternative to
the `[eval {rCa}]` syntax:
As for Tip 676, it doesn't appear to me to change the 12 rules, instead it introduces a new global function `=`. However, it also introduces a novel
DSL rather than using `eval`'s DSL. This seems to require a lot of
additional learning, particularly the dropping of the `$` for variable accesses, the fact that the string operators, `in`, `ni`, `eq`, `ne`, `lt`, `gt`, `le`, `ge` are not supported, the fact that `true` and `false` aren't supported, as well as the possible confusion over array accesses.
particularly painful for maintenance when a change to an expression using
`=` needed to be changed to one using `eval` because, say, a string operator needed to be used. The conversion from one form to another isn't straightforward (i.e., it would be easy to forget to add every `$`' where needed).
Tristan Wibberley <tristan.wibberley+netnews2@alumni.manchester.ac.uk> posted:
{=}{ ... } also seems NotRubbish to me on the same "regularity" factor I
was considering for rejecting the previously posted idea,
I was keen on the {=}{expression} form until I realised that it could only
be used as a separate word, it wouldn't work for a calculation embedded in
a string. Taking the same examples again:
set result {=}{$a + $b * $c}
would work, but
puts "Total: {=}{$sum + $tax}"
would not.
Tristan Wibberley <tristan.wibberley+netnews2@alumni.manchester.ac.uk> posted:
{=}{ ... } also seems NotRubbish to me on the same "regularity" factor I
was considering for rejecting the previously posted idea,
I was keen on the {=}{expression} form until I realised that it could only
be used as a separate word, it wouldn't work for a calculation embedded in
a string. Taking the same examples again:
set result {=}{$a + $b * $c}
would work, but
puts "Total: {=}{$sum + $tax}"
would not.
I've looked again at the two competing proposals for an alternative to
the `[eval {rCa}]` syntax:
Current: set c [eval {sqrt($a**2 + $b**2)}]
Tip 672: set c $(sqrt($a**2 + $b**2))
Tip 676: set c [= sqrt(a**2 + b**2)]
On 12/13/2025 1:28 AM, Mark Summerfield wrote:
I've looked again at the two competing proposals for an alternative to
the `[eval {rCa}]` syntax:
Current: set c [eval {sqrt($a**2 + $b**2)}]
Tip 672: set c $(sqrt($a**2 + $b**2))
Tip 676: set c [= sqrt(a**2 + b**2)]
I have a much more ambitious outlook for tcl expressions. I believe the
$ substitution should be reserved for string substitution, not "contents
of" as it is used in the (braced) expr command, where {$var op ...} has
to be a number, not an arbitrary string.-a If used with an operator like, {$var+5} and var contains "10/2" then an error is thrown.
.c create arc x-size y-size x+size y+size -start angle-15
-extent 30
Compare this create arc with the currently required expr:
.c create arc [expr {$x - $size}] [expr {$y - $size}] \
[expr {$x + $size}] [expr {$y + $size}] \
-start [expr {$angle - 15}] -extent 30
numberish {
cmd1 arg arg $[x+1]
cmd2 arg arg $[y/x]
}
numberish {
.c create arc !x-size !y-size !x+size !y+size !-start !angle-15 -extent 30 ...
...
...
}
What's the problem with
proc id {x} {return $x}
puts "Total: [id {=}{$sum + $tax}]"
or even
puts "Total: [approx {$sum + $tax}]"
numberish {
.c create arc !x-size !y-size !x+size !y+size !-start !angle-15 -extent 30 >> ...
...
...
}
I realise I've mixed multiple DSL ideas:
On 14/12/2025 03:28, Tristan Wibberley wrote:
numberish {
cmd1 arg arg $[x+1]
cmd2 arg arg $[y/x]
}
vs
numberish {
.c create arc !x-size !y-size !x+size !y+size !-start !angle-15 -extent 30 >> ...
...
...
}
Obvs. it might need to be extended with a numberish namespace
Interesting thread. Working from the assumption that in any/all of the proposed approaches, both "x" as well as "$x" would be interpreted to
refer to the value of "x", I find it odd that one would be able to mix
"x" and "$x" references in the same statement line and be OK.
While it could work as a package or a module, I am not sure of the value add, tbh.
On 12/14/2025 3:40 AM, Tristan Wibberley wrote:
numberish {
.c create arc !x-size !y-size !x+size !y+size !-start !angle-15
-extent 30
...
...
...
}
For a command that only accepts numerical arguments in the first 4
positions, why should one need to supply a sigil.
I'm not proposing that we change tcl all at once. The first step is to address the expr command for it's clutter and safety concerns when
called internally. I'm supporting the = command as a foundation for
future tcl improvements.
On 12/14/2025 6:40 AM, Tristan Wibberley wrote:
I realise I've mixed multiple DSL ideas:
On 14/12/2025 03:28, Tristan Wibberley wrote:
numberish {
-a-a cmd1 arg arg $[x+1]
-a-a cmd2 arg arg $[y/x]
}
vs
numberish {
.c create arc !x-size !y-size !x+size !y+size !-start !angle-15
-extent 30
...
...
...
}
Obvs. it might need to be extended with a numberish namespace
While it could work as a package or a module, I am not sure of the value
add, tbh.
BTW I think "=" is the wrong symbol because its a common relation in mathematics rather than an evaluation, excel kind of got it wrong. But I don't think its /terrible/. "#" might be better to indicate "a number approximated thusly:"
I'll carry on as if you agree '#' is best.
saito <saitology9@gmail.com> posted:
Interesting thread. Working from the assumption that in any/all of the
proposed approaches, both "x" as well as "$x" would be interpreted to
refer to the value of "x", I find it odd that one would be able to mix
"x" and "$x" references in the same statement line and be OK.
This is analogous to how one can currently write:
[expr $x * 2]
or
[expr {$x * 2}]
In most cases either will work, but the second is safer and more efficient.
Tristan Wibberley <tristan.wibberley+netnews2@alumni.manchester.ac.uk> wrote:
Unfortunately, while you are quite correct from a mathematics
viewpoint, that ship has long ago sailed for = meaning "evaluate
expression" in programming languages. Using = for "evaluate", while technically wrong mathematically, will fit with the built in
understanding anyone will have from programming languages as far back
as BASIC.
I'll carry on as if you agree '#' is best.
# is problematic because it is already used as the "commenting"
character
The = symbol, at least, has been mis-used to mean 'evaluate' for so
very long that there is no cognitive load for programmers seeing = in
code to have to disambiguate two very different meanings from context
clues. Only actual mathematicians will have some cognitive load in
seeing = used to mean evaluate.
On 15/12/2025 16:09, Rich wrote:
The = symbol, at least, has been mis-used to mean 'evaluate' for so
very long that there is no cognitive load for programmers seeing = in
code to have to disambiguate two very different meanings from context
clues. Only actual mathematicians will have some cognitive load in
seeing = used to mean evaluate.
I've only seen it used to mean evaluate in BASIC and Excel. I don't
remember seeing it anywhere else.
On 12/15/2025 4:18 AM, Colin Macleod wrote:
saito <saitology9@gmail.com> posted:
Interesting thread. Working from the assumption that in any/all of the
proposed approaches, both "x" as well as "$x" would be interpreted to
refer to the value of "x", I find it odd that one would be able to mix
"x" and "$x" references in the same statement line and be OK.
This is analogous to how one can currently write:
-a-a [expr $x * 2]
or
-a-a [expr {$x * 2}]
In most cases either will work, but the second is safer and more
efficient.
My example tried to highlight the pitfalls of treating identically
different combinations of: x, "x", {x}, $x, and perhaps more. I think
this is quite different the semantics of using braces where you learn it
as a core part of Tcl.
I'm now thinking about those places like lindex where an argument is
end-2 and stuff like that.
That's a DSL that could do with being generalised.
The message body is Copyright (C) 2025 Tristan Wibberley except
citations and quotations noted. All Rights Reserved except as noted in
the sig.
Regarding your concern about why there are various ways to use a variable:
see man tcl if on linux and read and understand the 12 rules in details, experiment based on what you find there.
Tristan Wibberley <tristan.wibberley+netnews2@alumni.manchester.ac.uk> posted:
I'm now thinking about those places like lindex where an argument is
end-2 and stuff like that.
That's a DSL that could do with being generalised.
In the Discussion section of TIP 676 I said:
Some of the string and list-related commands already support a restricted
form of numeric expressions for indices, e.g. [lindex $list end-2]. This
could be generalised in future by having them temporarily define end as
the appropriate value and run the = processing on index arguments.
While there are Tcl
commands that currently accept a variable name or a variable value, you cannot mix and match them willy-nilly. But the proposed solutions would, AFAICT, allow one to write "x + $x" to end up with a value of 2*x. That
is something I have not seen elsewhere and may end up doing more harm
than good.
I'm not sure it is a good idea to include single character function names in the base TCL set.
Things like:
proc a {...
are too useful at the command line.
For example I have my own take on a expr I call uexpr (it does math with units like ft sec kg watt ... etc).
package require uexpr
exposes the uexpr command at the global level.
There is an option in the uexpr pkgIndex.tcl for:
package require uexpr=
that aliases = to uexpr for convienence at the command line (= 3ft+6in=cm returns "106.68 cm")
However when I write a package "calc" to format calculations to generade .pdf files using pdflatex
and uexpr, I require uexpr, and use the canonical uexpr name in the package code
because the = alias might be preempted for some other purpose at the command line.
I think single character command names are too useful at the command line to be "taken" by the base TCL language or a widely used package.
daveb
Tristan Wibberley <tristan.wibberley+netnews2@alumni.manchester.ac.uk> posted:
I'm now thinking about those places like lindex where an argument is
end-2 and stuff like that.
That's a DSL that could do with being generalised.
In the Discussion section of TIP 676 I said:
Some of the string and list-related commands already support a restricted
form of numeric expressions for indices, e.g. [lindex $list end-2]. This
could be generalised in future by having them temporarily define end as
the appropriate value and run the = processing on index arguments.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 59 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 00:20:38 |
| Calls: | 810 |
| Files: | 1,287 |
| Messages: | 198,260 |