incr(3tcl)
π incr β bestie, we're doing MATH π
okay so real quick, this page lives in the Tcl Built-In Commands manual, section 3tcl, and it's about the single most iconic lil glow-up a variable can get. it's called incr. it adds. that's it. that's the whole vibe. π
β¨ NAME β¨
incr β increment the value of a variable
π SYNOPSIS π
incr varName ?increment?
π¦ DESCRIPTION π¦
so here's the tea: incr increments the value stored in the variable whose name is varName. the value of the variable MUST be an integer β like, non-negotiable, bestie, that's the vibe check. π«Ά
if increment is supplied, then its value (which also must be an integer, no exceptions, i'm so serious π) gets added to the value of the variable varName. if increment is not supplied, then 1 gets added to varName instead. default behavior = just add one. lowkey the most used line of Tcl in existence ngl.
the new value is stored as a decimal string in the variable varName, and it's also returned as the result. so you get the value AND the side effect. it's giving multitasking. it's giving main character energy. π
πΈ starting with the Tcl 8.5 release, the varName passed toincrmay be unset β and in that case it will be set to the value of increment, or to the default increment value of1. glow-up from nothing, we love to see it.
and one more lil situation, bestie: if varName indicates an element that does not exist of an array that has a default value set, then the sum of the default value and the increment (or 1) will be stored in that array element. π
π EXAMPLES π
add one to the contents of the variable x:
incr x
add 42 to the contents of the variable x:
incr x 42
add the contents of the variable y to the contents of the variable x:
incr x $y
add nothing at all to the variable x β and yes, this is genuinely useful, it's often used for checking whether an argument to a procedure is actually integral and generating an error if it is not:
incr x 0
like?? adding zero?? but it checks your types while it does it. not me being obsessed with a no-op. πβ¨
π SEE ALSO π
π₯ KEYWORDS π₯
add, increment, variable, value
okay bye bestie, go forth and increment responsibly π§ this was the incr(3tcl) page from the Tcl crew, and honestly? slay. periodt. πππ¦
π¦ where this page comes from
- debian trixie: tcl9.0-doc 9.0.1+dfsg-2
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- Copyright (c) 1993 The Regents of the University of California
- Copyright (c) 1994-1996 Sun Microsystems, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms