|
From: Colin M. <col...@ya...> - 2025-12-29 11:43:28
|
Dear All, In trying to answer sebres's criticism of the compiled code efficiency in my tip 676 implementation, I wrote some kludgy, ad-hoc compile-time type-checking. This allows me to skip doing a run-time check that a value is numeric when it comes from a command that always gives numeric results. I'm now wondering if a more general type-checking facility for Tcl could be worth exploring. My kludge could be extended to specify the return types and argument types for those built-in commands where this is possible. E.g. `llength` requires a list argument and returns an integer. A variant of `proc` could be introduced where one can specify argument and return types. Also we could have a facility to declare a variable with a fixed type in a similar way to how Tip 677 allows declaring a variable to be constant. A typed variable would have to be initialised with a legal value of that type, and could only be modified to another value which can be converted to that same type. Then, for example, an arithmetic expression whose variables were all known to be doubles could be evaluated without all the type-checking and conversion logic which is currently needed, perhaps giving a significant speedup. It should also be possible to do better error reporting, e.g. if the increment passed to `incr` has been declared as double, this error can be reported at compile time. Such errors could be picked up if and when the code is compiled, even if that specific command is not executed. This would address another of the perennial complaints against Tcl. Any thoughts, too un-Tcl-ish perhaps??? Season's Greetings, Colin. |