.. _readme-static: .. default-domain:: chpl Function-Static Variables ========================= .. warning:: This work is under active development. As such, the interface is unstable and expected to change. It is likely the final version of this feature will not be implemented using an attribute. .. contents:: Overview -------- Chapel has limited support for marking variables as 'function static'. Doing so causes them to have similar semantics to `C++ block-static variables `_. In other words, a variable declared as 'function static' will be initialized once when the function is first executed; subsequent calls to the function will re-use the existing value of the variable. This can be useful for re-using results of computations that do not change between function invocations. For instance, one might compute a lookup table on the first invocation of a function, and simply access that lookup table in subsequent runs. The following program demonstrates this, pre-computing the Fibonacci numbers: .. code-block:: chapel use CTypes; use Time; config param tableSize = 10000; proc computeExpensiveTable(seed1: real, seed2: real) { writeln("Computing an expensive table"); var toReturn: c_array(real, tableSize); toReturn[0] = seed1; toReturn[1] = seed2; for i in 2..