incr(n)

πŸ“¦
version 9.0.3 Β· 3 versions
, in alpine 3.23, alpine 3.24, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

✨ 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 variable varName you pass to incr is allowed to be unset! and if it is, it'll be set to the value of increment, or to the default increment value of 1. 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