|
|
|
|
|
by lilyball
620 days ago
|
|
I've long wished to have the free time to write a Tcl-derived language, because it really is so elegant in many ways, it just needs a bit of modernization in some areas. It's been years since I really thought much about this but I recall one of the things it's missing is closures (it does have lambdas at least). Reading through this article, the memoize implementation does have an issue which is if the memoized command wants to call uplevel or upvar it'll get the wrong stack frame. If I were writing this I'd structure it so it's used like proc myMemoizingProcedure { ... } {
memoize {
... the rest of the code ...
}
}
such that it can just `uplevel` the code. Or better yet I'd make `memoize` replace the `proc` keyword (or perhaps `memoize proc myMemoizingProcedure …`).EDIT: I suppose memoizing makes no sense in a procedure that wants to use upvar or uplevel though, because memoizing only works for pure functions. |
|
https://wiki.tcl-lang.org/page/Closures
https://wiki.tcl-lang.org/page/Emulating+closures+in+Tcl
TCL 9 has surely fiddled with tcl_ObjType I hope, but it doesn't seem like it from a glance.