|
From: EricT <tw...@gm...> - 2025-10-17 21:22:31
|
Hello Tcl Core Team,
I have developed a working prototype implementation of TIP 672, which adds
the $(expression) syntax as a more intuitive alternative to [expr
{expression}].
Repository: https://github.com/rocketship88/tcl-tip-672-prototype
The implementation is minimal, modifying only two files (tclParse.c and
tclNamesp.c) with approximately 100 lines of changes. The key modification
converts the existing two-way branch in Tcl_ParseVarName to a three-way
branch, with the new path handling $(...) by creating a synthetic [expr
{...}] command string.
Key Accomplishments:
Full bytecode compilation: The synthetic string approach integrates
seamlessly with the existing compiler, producing identical optimized
bytecode as [expr {...}]. The disassembler output (shown in the README)
demonstrates efficient variable loading with no runtime parsing overhead.
Proven approach: Jim Tcl has used this syntax successfully for years
Comprehensive testing: Works correctly with string interpolation, variable
scoping, error handling, and interactive mode
Known Limitations:
Memory leak: The synthetic string is allocated but not tracked for cleanup
in Tcl_FreeParse. This requires core team guidance on the preferred
solution (modify Tcl_Parse structure vs. thread-local tracking).
Error messages: Currently show the synthetic command rather than the
original $(...) syntax, though this is arguably helpful for debugging.
Questions for the Team:
What is the preferred approach for tracking synthetic strings for cleanup?
Is this prototype architecture acceptable for Tcl 9.x?
Are there concerns with the synthetic string approach that I should address?
The complete implementation with side-by-side diffs is available in the
repository. I'm happy to refine the code based on your feedback and would
appreciate any guidance on moving this forward.
Best regards,
Eric
|