defer(3tcl)
β¨ defer β bestie we are doing CLEANUP β¨
okay so this is defer(3tcl) from the tcllib manual set, and it is literally the "defered execution ala Go" page. yes the typo is canon, we respect it π
πΈ NAME πΈ
defer β Defered execution. that's it, that's the name, she's simple and she serves π«Ά
π¦ SYNOPSIS π¦
package require Tcl 8.6 9
package require defer ?1.1?
::defer::defer ?command? ?arg1? ?arg2? ?argN...?
::defer::with variableList script
::defer::autowith script
::defer::cancel ?id...?
π DESCRIPTION π
so the defer commands let you, the developer, schedule actions to happen as part of the current variable scope terminating. it's giving cleanup-activity energy, and honestly that's the whole point.
the way this hits: because the defered actions always execute, and they always execute in the reverse order from which the defer statements themselves execute, you can schedule the cleanup of a resource (say, a channel, bestie) the second you acquire it. then, later, if the procedure or lambda ends β whether that's because of an error, or an explicit return β the cleanup of that resource will always occur. no cap. that's the whole vibe. πβ¨
π COMMANDS π
::defer::defer ?command? ?arg1? ?arg2? ?argN...?β defers execution of some code until the current variable scope ends. every argument gets concatenated together to form the script that runs at deferal time. you can use multiple defer statements and they execute last-in, first-out. the return value is an identifier, and you can hand that identifier todefer::cancellater. π::defer::with variableList scriptβ defers execution of a script, but it copies the current value of some variables into the script β the names of those variables are the ones you list in variableList. the script acts like a lambda, but it executes at the same level as thedefer::withcall. the return value is the same as::defer::defer. π::defer::autowith scriptβ same as::defer::with, except it uses all local variables in the variable list. lazy girl behavior and we love her for it πΈ::defer::cancel ?id...?β cancels the execution of a defered action. the id argument is the identifier returned by::defer::defer,::defer::with, or::defer::autowith. you can supply any number of arguments, and all of the IDs supplied will be cancelled. periodt. β¨
π EXAMPLES π
package require defer 1
apply {{} {
set fd [open /dev/null]
defer::defer close $fd
}}
look at her go π¦ open the fd, immediately schedule the close, let the scope do the rest. iconic behavior fr fr.
π REFERENCES π
[1]
π AUTHORS π
Roy Keene π
π BUGS, IDEAS, FEEDBACK π
ngl, this document, and the package it describes, will undoubtedly contain bugs and other problems. so please report such in the category defer of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. and please also report any ideas for enhancements you may have for either the package and/or the documentation β we want all of it, bestie π«Ά
when proposing code changes, please provide unified diffs, i.e the output of diff -u. yes literally that.
note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. iykyk π
π KEYWORDS π
cleanup, golang
β CATEGORY β
Utility
πΈ COPYRIGHT πΈ
Copyright (c) 2017, Roy Keene
okay that's the whole page, mwah π this was the defer(3tcl) manpage from tcllib, version 1.1 β go forth and clean up your resources, bestie, you've got this πβ¨π«Ά
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- Copyright (c) 2017, Roy Keene
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms