I have an m-file solution to static variables. It doesn't provide as good
of static variable implimentation as if it was built-in to octave, but it
only puts one extra variable into the global name space no matter how many
static variables exist in a program. This may be useful.
Also I think it could be an initial test case for the design of
a built-in static variable implementation.
An m-file implementation could be made to be as good as a built-in version
if in a user-defined function, you could:
1) get the name of the function that called the current function
2) get the name of the output arguments in calling function
3) attach a function (or set of functions) to always be called
upon exit from a user-defined function.
Well, that was my two cents worth on static variables.
%The file static.m follows:
%usage: val=static(calling_function_name, variable_name,
% current_value, "init");
%or: val=static(calling_function_name, variable_name, current_value);
%This function impliments a limited form of static variables in octave
%In order to put a static variable, x, with an initial value of: 0, in
%the function dog:
% 1) put the following line near the begining of function, dog:
% x = static("dog","x",0,"init");
% 2) at the end of the function dog put:
%The advantage over this method over global variables is that it only
%puts one variable name in the global name space no matter how many
%static variables are used and that you can use short non-globally
%unique names in the local function.
%The disadvantage of this method over global variables is that in this
%method there are two copies of the variables. (This is probably only
%important if you have large matrices that you want to make static.)
STATIC_variable_list.null = 0;