| 
     
      
      
      From: Colin M. <col...@ya...> - 2025-10-25 16:17:19
      
     
   | 
(Sorry, I just can't stay away from the bikeshed)  :-)
Kevin mentions the idea of having expression evaluation interpret bare 
words as variable references without requiring $ in front.
On 21/10/2025 03:30, Kevin Kenny wrote:
> (I'd actually favor {$} over {=}, and instead reserve {=} for the 
> possibility of a new 'little language' for less cumbersome expressions 
> (in particular, automatic $-substitution of barewords, and 
> implementation of = for assignment.
It occurs to me now that an expr alternative which does this can avoid 
the whole double substitution issue.  If you can write x*2-3 instead of 
$x*2-3 there's no need to brace the expression because x cannot be 
prematurely substituted before the expression code sees it.
If `=` was defined to concatenate its arguments and then treat the 
result as an expression where barewords are interpreted as variable 
references, you could write [= x*2-3] to do this calculation in a form 
which is both safe, compact, and fully conforms to the existing 
dodekalogue rules.
As with my proposal in tip 676, this probably needs to be restricted to 
numeric and boolean operations, string literals would be difficult to 
accommodate.
Of course it would still be possible to write $ substitutions within the 
expression, but this would not normally be needed and the documentation 
should warn that this is risky.
Substitutions of [command] would work as long as command returns a 
single numeric or boolean value. However if that value gets concatenated 
into a string its numeric representation will be shimmered away. It may 
be possible to avoid this if [command] is given as a separate argument, 
i.e. [= 2* [llength $list] -1] not [= 2*[llength $list]-1], by checking 
for a numeric representation before concatenating arguments.
However the main usefulness of this facility would be for short, simple 
expressions like [= x*2-3] (9 chars) where the verbosity of [expr 
{$x*2-3}] (15 chars) is cumbersome.  The proposed $(($x*2-3)) is longer 
(11 chars) *and* requires an update to the dodekalogue, something not to 
be undertaken lightly.
Colin.
 |