unset(n)
πΈ unset(n) β the Tcl Built-In Commands girlies know this one π
okay bestie, so <rainbow>unset</rainbow> is literally the "delete that" button for variables. Like, it's giving cleanup era. β¨
β¨ NAME β¨
unset β Delete variables ποΈπ
π SYNOPSIS π
unset ?-nocomplain? ?--? ?name name name ...?
π¦ DESCRIPTION π¦
So this command removes one or more variables, periodt. Each name is a variable name, and you can write it in any of the ways that are acceptable to the set command β same vibe, same rules, iykyk. π
Now here's the tea on arrays, because this part matters:
- If a name refers to an element of an array, then just that element gets removed, and the rest of the array is completely unbothered. No collateral damage. π«Ά
- If a name is an array name with no parenthesized index, then the entire array is deleted. Gone. Poof. π
And the result? The unset command returns an empty string as its result. That's it. That's the whole output. Very demure, very minimal. πΈ
π the options, bestie
-nocomplainβ if you pass this as the first argument, then any possible errors are suppressed. Live your life, no complaining allowed. π One thing though: this option may not be abbreviated, and that's on purpose β it's so it doesn't get confused with a possible variable name. Like, we need to disambiguate, okay?? π--β this one indicates the end of the options. You should use it if you wanna remove a variable that has the same name as any of the options. Basically it's the "okay no more option talk, everything after this is a name" signal. β
π the error situation (read this one, fr fr)
If an error happens during variable deletion, then any variables after the named one that caused the error are NOT deleted. So it's not like a full rollback, it just stops. Bestie, be aware. π
An error can occur when:
- the named variable does not exist, or
- the name refers to an array element but the variable is a scalar, or
- the name refers to a variable in a non-existent namespace.
lowkey these are the three little gremlins that ruin your unset moment. know them, respect them. πβ¨
π₯ EXAMPLE π₯
okay so here's the iconic one β we're making an array that maps some numbers to their squares, and then we remove the array elements for non-prime numbers. slay.
array set squares {
1 1 6 36
2 4 7 49
3 9 8 64
4 16 9 81
5 25 10 100
}
puts "The squares are:"
parray squares
unset squares(1) squares(4) squares(6)
unset squares(8) squares(9) squares(10)
puts "The prime squares are:"
parray squares
see how we're just yeeting 1, 4, 6, 8, 9, and 10 out of existence? the primes stay. main character energy honestly. πβ¨
π SEE ALSO π
π KEYWORDS π
- remove
- variable
and that's the whole page bestie!! this one came from the Tcl Built-In Commands crew, version 8.4, and yeah β the page itself is dated to that same 8.4 era, so give it a lil nostalgic moment. πβ¨ bye ily, go unset something responsibly ππ¦
π¦ 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
- centos-stream 10: tcl-doc 1:8.6.13-4.el10 Β· TCL AND GPL-3.0-or-later WITH bison-exception-2.2 AND BSD-3-Clause
- centos-stream 9: tcl-doc 1:8.6.10-7.el9 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- 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 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- Copyright (c) 2000 Ajuba Solutions
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms