unset(n)

πŸ“¦
version 9.0.3 Β· 2 versions
  • 9.0.3 Β· alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, fedora 43, fedora 44, nixos 26.05, opensuse-leap 16.0 (latest)
  • 9.1.0 Β· nixpkgs unstable
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, fedora 43, fedora 44, nixos 26.05, opensuse-leap 16.0

🌸 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