I Language: Variable Self-Modification

Posted June 18, 2011 by User 1

Increment, decrement, multiply by self, etc.

Operators for these functions, long overdue, have now been implemented. Currently, the following operators have been implemented:

(var) += (num) Increment
(var) -= (num) Decrement
(var) *= (num) Multiply
(var) /= (num) Divide
(var) %= (num) Modulo
(var) ^= (num) Power
(var) :: (num) Append

In addition to being syntactic sugar, these may also offer performance gains, but only in some instances.

The only of these operators with appreciable difference are += and -=, mainly because addition and subtraction are extremely fast compared to the other operations. Under normal circumstances where a variable is being incremented or decremented, these operators will be about 80% slower than using a = a + 1 or the equivalent. However, if the variable to be incremented or decremented is indexed in a table (ie. a[1] = a[1] + 1), then the difference is made up for. If the variable is inside two tables (ie. a[1][1] = a[1][1] + 1), then there is a 25% gain in speed.

Multiplication and division show similar but scaled down results (about 10% as extreme). Modulo, power and append operations are scaled < 1% from the above results.

Go to I Language project page
More news from the I Language project.

Go to all projects' news index

Copyrighted © 2007-2023, The Caglow Project.
Material is available under AL.