Let Arithmetic

Ion supports applying some basic arithmetic, one operation at a time, to string variables. To specify to let to perform some arithmetic, designate the operation immediately before =. Operators currently supported are:

  • Add (+)
  • Subtract (-)
  • Multiply (*)
  • Divide (/)
  • Integer Divide (//)
  • Modulus (%)
  • Powers (**)

Individual Assignments

The following examples are a demonstration of applying a mathematical operation to an individual variable.

let value = 5
echo $value
let value += 5
echo $value
let value -= 2
echo $value
let value *= 2
echo $value
let value //= 2
echo $value
let value **= 2
echo $value
let value /= 2
echo $value
5
10
8
16
8
64.0
32.0

Multiple Assignments

It's also possible to perform a mathematical operation to multiple variables. Each variable will be designated with a paired value.

let a b = 5 5
echo $a $b
let a b += 5 5
echo $a $b
let a b -= 2 2
echo $a $b
let a b *= 2 2
echo $a $b
let a b //= 2 2
echo $a $b
let a b **= 2 2
echo $a $b
let a b /= 2 2
echo $a $b
5 5
10 10
8 8
16 16
8 8
64.0 64.0
32.0 32.0