**persistence**,
a Python code which
demonstrates how to initialize, get, or set data stored
within a function, using static/persistent/saved/local memory.

This type of data storage is sometimes referred to as "static memory" or "persistent memory" or "saved memory".

Several examples are offered here, each embodied in a function.

- constants() stores the value of three physical constants, and returns them. It is not very ambitious.
- counter() "remembers" how many times it has been called, and prints this value.
- abc() stores the value of three real numbers, which are initialized to 1, 2, and 3. The user can request the current values, or request that they be printed, or can set them to new values.
- stats() accepts, one at a time, a sequence of real numbers. It internally updates the sum, min, mean, max, variance and standard deviation of the entire sequence, and can report the current values of these quantities at any time.
- byname() internally stores three variables. The user can access any one of these variables, by naming the kind of access, naming the variable to be accessed, and the new value if any, to be assigned to it.

The computer code and data files made available on this web page are distributed under the GNU LGPL license.

**persistence** is available in
a C version and
a C++ version and
a FORTRAN90 version and
a MATLAB version and
an Octave version and
a Python version and
an R version.

- persistence.sh, runs all the tests.

- abc.py, stores, saves, and returns variables "a", "b", "c", using the form "[aout,bout,cout]=abc(ain,bin,cin)";
- abc.sh, runs all the tests.
- abc.txt, the output file.

- byname.py, sets, gets, prints or resets any of three variables "alpha", "beta", "gamma", which are referenced by name, using actions "print", "get", "set", or "reset", using the form "value_out=byname(action,name,value_in)";
- byname.sh, runs all the tests.
- byname.txt, the output file.

- constants.py, saves and returns constants "g", "c", "n", using the form "[g,c,h]=constants()";
- constants.sh, runs all the tests.
- constants.txt, the output file.

- counter.py, prints the number of times it has been called, using the form "counter()";
- counter.sh, runs all the tests.
- counter.txt, the output file.

- stats.py, initializes, updates, and outputs running values of statistical quantities of a sequence of data supplied one value at a time, using the form [n,x_sum,x_min,x_mean,x_max,x_var,x_std]=stats(x).
- stats.sh, runs all the tests.
- stats.txt, the output file.