Reputation: 849
I have been looking for a way how to define persistent local variables inside the Scilab function. It could be said that I have been looking for a way how to define equivalent of the static local variables known from the C programming language in the Scilab function. Can anybody help?
Upvotes: 1
Views: 289
Reputation: 911
There are at least 2 ways to get a similar feature:
using global variables (to get some static):
https://help.scilab.org/docs/6.1.1/en_US/global.html
This is likely the most "standard" way.
You may define them in a local scope (for instance in a
function), but then there is no way to restrict the access to
them to the place where they have been defined.
using variables in a TCL "interpreter":
https://help.scilab.org/docs/6.1.1/en_US/TCL_CreateSlave.html https://help.scilab.org/docs/6.1.1/en_US/TCL_SetVar.html https://help.scilab.org/docs/6.1.1/en_US/TCL_GetVar.html
A TCL interpreter is a kind of "namespace". It is also a global object. You may defined as many interpreters as you want. But not all types of data can be recorded as a TCL variable. And all data are (recorded and) retrieved as strings (and only in single precision for decimal numbers. May be it's possible to go beyond by using some TCL options).
In the opposite, there is no data type limitations for global variables, that are recorded as is, without any conversion into strings. But there is no way to define "global namespaces" (may be as fields of a global structure..)
Upvotes: 1