|
From: Florent M. <flo...@gm...> - 2025-10-22 18:19:00
|
Another alternative proposal :
set x [($y+1)]
It is very readable, easy to write, there is eventually a unicode version
set x 〖$y+1〗
1 . We define a new kind of substitution
RULE [7'] Expression substitution :
If a word contains an open bracket *«** [ »* immediately followed by an
open parenthesis « ( », then Tcl performs an Expression substitution. To
do this it invokes the Tcl interpreter recursively to process the
characters following the open parenthesis as a Tcl mathematical
Expression. The Expression must be terminated by a close bracket « *] »
*immediately preceded by a closed parenthesis « ) ». The result of the
expression is substituted into the word in place of the
brackets-parenthesis and all of the characters between them. There may
be any number of expression substitutions in a single word. Expression
substitution is not performed on words enclosed in braces.
2. We create the test in ParseToken
... else if (*src == '[') {
if (src[1] == '(') {
// Expression substitution
// must finish by « )] »
// doesn't know how to do it...
} else {
// Command substitution
}
3. we create a -noexpr switch in the subst command
....
Examples :
inline expression : string range "my long sentence" 0 end-[($x+2)]
With native list expr enancement : .c create rectangle {*}[( $X , $Y,
$X+100, $Y+100 )]
With multiples instructions enhancement : set multiexpr [( x = 1; y =
2; $x-$y, $y-$x )]
Readable, easy to type, test logically positionned in the C source code,
no double substitution, avoiding confusion with variable substitution :
This is the solution !
Florent
Le 22/10/2025 à 15:52, Zaumseil René a écrit :
>
> And how will this be documented? Imho it should be mentioned in the
> dodecalogue.
>
> Currently the used syntax is only used as array variable and not as
> math command.
>
> I remember the big discussion on {*} syntax here.
>
> Again, is this change really more readable and useable?
>
> Is the benefit worth the additional syntax.
>
> Why not create real benefit with p.e. a multiple set command ala tip 674.
>
> Or a new math command without need of $.. access to variables.
>
> Regards
>
> rene
>
> *Von:*Florent Merlet <flo...@gm...>
> *Gesendet:* Mittwoch, 22. Oktober 2025 15:39
> *An:* tc...@ro...
> *Cc:* et...@ro...; tcl...@li...
> *Betreff:* [Ext] Re: [TCLCORE] TIP 672 Implementation Complete - Ready
> for Sponsorship
>
> So, everybody in the core team agree with the implementation of a new
> math-Expression substitution as a memlink command into the procedure
> in charge of variable name substitution ?
>
> Le mer. 22 oct. 2025, 14:07, EricT <tw...@gm...> a écrit :
>
> Hi everyone,
>
> I wanted to update you on the status of TIP 672 (expression
> substitution syntax).
>
> The prototype implementation is now complete and available at:
> https://github.com/rocketship88/tcl-tip-672-prototype
>
> The implementation has been parameterized to support both
> discussed approaches with a simple compile-time flag:
> - Mode 1: $(expr) syntax
> - Mode 2: $=(expr) or $^(expr) - configurable character
>
> Key features:
> - Comprehensive test suite (82 tests covering edge cases)
> - Minimal code changes (~100 lines)
> - Clean integration with existing parser
> - Full Tcl test suite passes (only 3 expected differences)
>
> There is one known issue: a minor memory leak in the synthetic
> command strings that will need attention during integration.
>
> At this point, I need a sponsor to upload the code to a TIP branch
> on Fossil so the core team can review and decide whether to adopt
> the TIP and, if so, which syntax to use. I'm available for any
> collaborative work, questions, or modifications needed.
>
> I'm grateful for all the feedback and support from the community.
> I look forward to the next steps in the process.
>
> Best regards,
>
> Eric
>
> _______________________________________________
> Tcl-Core mailing list
> Tcl...@li...
> https://lists.sourceforge.net/lists/listinfo/tcl-core
> |