On Mon, 5 Nov 2007, Ignacio Diaz-Emparanza wrote:
I suppose you remember my message about building a function with one
input
series and several output series, that I wanted to be named accordingly to
the input series (see
http://lists.wfu.edu/pipermail/gretl-users/2007-June/001722.html ).
I needed a "string" parameter in a function, but given that string parameters
are not allowed in a function I solved my problem using an external string
inside my function (I know this is not very smart but ... ).
I agree wholeheartedly on the fact that it should be possible to use
strings as function arguments. Every time I tried to write complex
user-level sets of functions, this limitation was quite painful.
The issue is not easy, though. From my understanding of the code, it works
more or less like this (Allin, please correct me where I'm wrong -- it
could be ALL wrong): every user-defined string is contained in a static
array called saved_strings; as such, no matter how deep function nesting
is, all strings are potentially accessible. However, we keep track of the
level at which each string is defined, so that the string is in fact
usable only at that level.
We could work around Ignacio's problem in more than one way:
1) let strings be visible everywhere. Definitely dangerous.
2) let strings defined in the caller function be visible in the called
functions. Less dangerous, but still nasty.
3) have separate saved_strings structures for each function call.
Possibly, quite expensive.
4) enable GRETL_TYPE_STRING as a function argument and store a copy of the
string in the global array, only marked at a different level. The copy
should be destroyed on function exit. This would probably require
non-trivial modifications to the existing code, plus an appropriately long
time for debugging.
As you may gather, I would prefer approach 4. The real question now is:
should this be a show-stopper for 1.6.6?
Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche
r.lucchetti(a)univpm.it
http://www.econ.univpm.it/lucchetti