Pure function

[clarification needed] The second point ensures that the only sequence usable as an argument must change with each I/O action; the first allows different calls to an I/O-performing function to return different results on account of the sequence arguments having changed.

[3][4] The I/O monad is a programming idiom typically used to perform I/O in pure functional languages.

The outputs of a pure function can be precomputed and cached in a look-up table.

A C program for cached computation of factorial (assert() aborts with an error message if its argument is false; on a 32-bit machine, values beyond fact(12) cannot be represented anyway.

Nevertheless, in a single-threaded environment, the following C++ code can be optimized such that the value of s.length() is computed only once, before the loop.