Re:Why is Tcl syntax so weird (2013)
by blacksqr on Sunday November 07, 2021 @11:04PM
(#29146043)
Re [1]: the libraries that delete an object when it goes out of scope use Tcl's built-in "trace" command, which lets you execute code when a command terminates or when a variable is deleted, among other events. So no, it's all done in pure Tcl.
[ Parent
| on HN ]
Oh it looks like I misremembered. I thought the API I had used was something like `set doc [foo parse $input]` and the document would go away when the variable does. I found it, it's the tDOM library, and it was actually `dom parse $xml doc` that does the automatic freeing, whereas `set doc [dom parse $xml]` requires manual deletion. So it probably is using trace.
This is how the "defer" [0] command (from tcllib) in Tcl works.
[0] https://core.tcl-lang.org/tcllib/doc/tcllib-1-19/embedded/ww...