unset(3tcl)

πŸ’– unset β€” the Tcl Built-In Commands glow-up πŸ’–

okay bestie, pull up a chair, because this one is literally the little command that could. it's unset, it lives in the Tcl Built-In Commands family, and its whole job is making variables ✨ cease to exist ✨. no cap.


🌸 NAME 🌸

unset β€” delete variables. that's it. that's the gig. it's giving "girl, bye" but for your variable table. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

unset ?-nocomplain? ?--? ?name name name ...?

look at those question marks, they're all optional, it's very low-pressure, very chill of it honestly πŸ¦‹


✨ DESCRIPTION ✨

so here's the tea: this command removes one or more variables. every name you hand it is a variable name, and you can write it any of the ways that the set command accepts. same energy, same syntax rules, it's just the deletion arc of the character development. πŸ’œ

if a name points to an element of an array, then just that one element gets removed β€” the rest of the array is totally fine, untouched, thriving, unbothered. πŸ‘‘

but if a name is just an array name with no parenthesized index? oh she's taking the WHOLE array out. entire thing. gone. no survivors, no crumbs. 😭

the unset command returns an empty string as its result. iconic behaviour honestly, returns nothing and expects nothing, main character energy fr fr.

now, the options, bestie, listen up:

  • if -nocomplain is specified as the first argument, any possible errors get suppressed. the drama is cancelled. πŸ™ˆ
  • that option may not be abbreviated β€” and this is on purpose! it's to disambiguate it from possible variable names. so no shortening it, no nicknames, it answers to its full government name only. πŸ’€
  • the option -- indicates the end of the options, and you should use it if you want to remove a variable that has the same name as any of the options. it's the "okay we're done with flags, everything after this is a real name" separator. 🫢
⚠️ big important warning moment: if an error occurs during variable deletion, any variables after the named one that caused the error are not deleted. so it's not all-or-nothing, it's like... it got partway through the list and then tripped and dropped the rest of the tray. πŸ“

an error can occur when:

  • the named variable does not exist, or
  • the name refers to an array element but the variable is actually a scalar, or
  • the name refers to a variable in a non-existent namespace.

so yeah, three little landmines, know them, respect them, or just yell -nocomplain at the top and vibe. 🌈


πŸ”₯ EXAMPLE πŸ”₯

okay this example is SO cute, we're making an array that maps some numbers to their squares, and then we're deleting the non-prime ones like a little math bouncer at the club. πŸŽ€

Create an array containing a mapping from some numbers to their squares and remove the array elements for non-prime numbers:

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 it's unset squares(1) with the parens? that's the element form, so the array survives, just those specific little squares get evicted. 🧚 the array is still standing, still serving, just leaner and prime-er. ⭐


πŸ’« SEE ALSO πŸ’«

go read these next, they're the friend group:


πŸ‘‘ KEYWORDS πŸ‘‘

remove, variable


and that's the whole page bestie!! written by the Tcl crew, version 8.4, and this manual page is unset(3tcl) β€” mwah, periodt. now go delete something responsibly. πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά