incr(n)
β¨ incr(n) β the glow-up button for your variables β¨
okay bestie, imagine a variable that just... gets bigger. that's it. that's the whole command. and yet it's lowkey one of the most-used things in all of Tcl. we love a humble icon π
πΈ NAME πΈ
incr β Increment the value of a variable
π SYNOPSIS π
incr varName ?increment?
π DESCRIPTION π
So here's the tea: incr takes the value sitting inside the variable named varName and bumps it up. that value has to be an integer, no exceptions, no vibes-based math π«Ά
If you hand it an increment, that value (which also has to be an integer, obviously, we're not animals) gets added to whatever's in varName. If you don't hand it an increment, it just adds 1. simple. clean. iconic.
The new value gets stored as a decimal string back in the variable varName, and it's also returned as the result. so you get the answer twice, like a bestie who says "love you" and then says "love you" again π
β¨ Starting with the Tcl 8.5 release β¨ β the variablevarNameyou pass toincris allowed to be unset! and if it is, it'll be set to the value ofincrement, or to the default increment value of1. glow-up from nothing, literally main character energy.
And one more lil situation, no cap: if varName points at 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. the array just... conjures it. we love a generous queen π
π 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 β this one is often useful for checking whether an argument to a procedure is actually integral and generating an error if it is not:
incr x 0
π yes, adding zero does something. it's the vibe check for "is this thing actually an integer". incr x 0 will absolutely yell at you if it isn't. not me using math as a type checker fr fr.
π¦ SEE ALSO π¦
β KEYWORDS β
- add
- increment
- variable
- value
and that's the whole page, bestie π this was the incr(n) manual page from Tcl Built-In Commands, living in the Tcl distribution. go forth and make your numbers bigger. periodt. π
β¨
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· 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
- nixpkgs unstable: tcl 9.1.0
- 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