On Thu, 18 Jan 2007, Ignacio Díaz-Emparanza wrote:
You may see my problem in the script below. The function tries
to linearize automatically a list os series (interpolate missing
observations and correct outliers) trough TRAMO...
You now have (in CVS and the Windows snapshot) these things:
* You can do "set shell_sync on" to make the shell command work
synchronously. This is tested on Linux. Windows requires
different code to do that and I've added what I think is suitable
code but it's not yet tested.
* You can use the "append" command inside a loop.
However, these things by themselves will not make the script do
all you want it to. The structure of your script is
function (list, etc)
loop across list members
generate transformation using tramo
add to dataset with "append"
open data set
call function on list
OK, here's the problem: as you go through the loop inside the
function the various linearized series will be added OK, but then
when the function exits they will all be destroyed, since they are
variables local to the function and are not returned.
There are a few possible work-arounds for this, 2 of which I'll
mention for reference, and then a "proper fix" which is in
place but not yet well tested.
workaround 1: have the function process just one series, and
return the new series. The caller assigns the new series to an
workaround 2: the function processes several series, packs them
into a matrix, and returns the matrix. OK, except that this puts
the burden of dealing with a matrix onto the caller.
"Proper fix": a function can return a list. As the new series are
generated they're added to a list, which is then returned. Up
till now functions could not return lists, but it turns out this
is not very difficult to implement, so I've done it. When a
variable inside a function is referenced in a list that is
returned and assigned, that variable is _not_ destroyed on exit
from the function.
Here's a simple example of how things should be structured.
function make_cubes (list xlist)
list retlist = null
loop foreach i xlist --quiet
series $i3 = $i^3
list retlist = retlist $i3
return list retlist
list xlist = 3 4
list cubelist = make_cubes(xlist)
print xlist cubelist --byobs