On Fri, 18 Jul 2008, Ignacio Diaz-Emparanza wrote:
Reading Jack's message it seems that the solution causes many
problems.
I think a solution may be leaving the things as initially were, and creating
an "--overwrite" switch for the "return" command.
gretl may then cause an error when executing a function that contains
a "return" command without the "--overwrite" switch, but complete
the
function (overwriting the external variables) when the --overwrite switch is
active.
Unfortunately, it's not so simple: the problem is name clashes inside
functions. Lists are very handy, but they implicitly violate the principle
of encapsulation, because they carry into the function namespace variable
names defined outside.
For example: consider the following script:
<script>
function my_ols(series x, list X)
ols x X
end function
nulldata 10
y = normal()
x = normal()
list L = const x
ols y L
my_ols(y, L)
</script>
Easy, no? If you run it without PROTECT_LISTS, you'll see something is
wrong :-)
What happens here is that the list X contains a variable whose name
is "x". How is the ols command supposed to know the difference between the
series _internally_ named x (argument 1) and the one passed via the list?
Notice that in this case there is no overwriting involved: the issue just
revolves around the possibility (that exists with PROTECT_LISTS=0) that
two distinct objects may have the same name inside a function.
Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche
r.lucchetti(a)univpm.it
http://www.econ.univpm.it/lucchetti