local(n)
β¨ local(n) β the itcl girlies' guide to local objects β¨
okay so bestie, this is the local page from itcl (that's [incr Tcl], the object-oriented glow-up for Tcl) π
πΈ NAME πΈ
itcl::local β creates an object that is local to a procedure. that's it, that's the vibe π«Ά
β¨ SYNOPSIS β¨
itcl::local className objName ?arg arg ...?
π DESCRIPTION π
okay so the local command creates an [incr Tcl] object that is local to the current call frame. the moment that call frame dips out (goes away), the object gets automatically deleted β no cleanup code, no tears, no mess πβ¨
it's giving extremely useful for making objects that are local to a procedure. like, you want a lil guy that lives and dies with your proc? this is the command. periodt.
π as a side effect, this command creates a variable named"itcl-local-xxx", wherexxxis the name of the object that is created. this variable is the one keeping watch π β it detects when the call frame is destroyed and automatically deletes the associated object. so like, don't be weird about that variable, it's the object's emotional support variable fr fr.
π EXAMPLE π
in the following example, a simple "counter" object is used within the procedure "test". the counter is created as a local object, so it is automatically deleted each time the procedure exits. the puts statements in the constructor/destructor show the object coming and going as the procedure is called β main character entrances and exits only π
itcl::class counter {
private variable count 0
constructor {} {
puts "created: $this"
}
destructor {
puts "deleted: $this"
}
method bump {{by 1}} {
incr count $by
}
method get {} {
return $count
}
}
proc test {val} {
local counter x
for {set i 0} {$i < $val} {incr i} {
x bump
}
return [x get]
}
set result [test 5]
puts "test: $result"
set result [test 10]
puts "test: $result"
puts "objects: [itcl::find objects *]"
π¦ KEYWORDS π¦
classobjectprocedure
and that's the whole page bestie!! π this came from the itcl source, it's the local(n) manual page β no date on it, so we're just crediting the itcl era it lives in π go make some objects that know when to leave the party π§
π¦ where this page comes from
- alpine 3.22: tcl-doc 8.6.16-r0 Β· TCL
- alpine 3.23: tcl-doc 8.6.17-r0 Β· TCL
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl-doc 8.6.17-r1 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- arch rolling: tcl 8.6.16-1 Β· TCL
- fedora 43: itcl 4.3.2-1.fc43 Β· TCL
- fedora 43: itcl 4.3.2-2.fc43 Β· TCL
- fedora 44: itcl 4.3.2-3.fc44 Β· TCL
- nixos 26.05: tcl 9.0.3
- nixpkgs unstable: incrtcl 4.2.3
- nixpkgs unstable: tcl 9.1.0
- opensuse-leap 16.0: tcl 8.6.15-160000.2.2 Β· TCL
- opensuse-leap 16.0: tcl 8.6.15-160000.2.2 Β· TCL
- opensuse-leap 16.0: tcl 8.6.15-160000.2.2 Β· TCL
- opensuse-leap 16.0: tcl 8.6.15-160000.2.2 Β· TCL
- Copyright (c) 1993-1998 Lucent Technologies, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms