Subject: Re: [Gretl-devel] Sugestion: new function called varnames
On Tue, 5 Aug 2014, Allin Cottrell wrote:
> On Mon, 4 Aug 2014, Logan Kelly wrote:
>
>> Quick suggestion. Could a function called varnames() be added that is
>> like varname() except it returns an array with the names of variables
>> in a list. For example:
>
> varname() already does that, except that since it predates string
> arrays what it returns when given a list argument is a single string
> containing the names of the member series separated by commas.
If we're serious on arrays (as I think we should be), we should have all
functions with similar purposes return arrays. Clearly, this introduces the
issue of backward compatibility. Would you consider it useful to have a
function turning a space (or comma, ot tab, or whatever) separated string
into a string array? This way, you could preserve backward compatibility for
old scripts but also enjoy the power and flexibility of array, as in
<hansl>
list X = a b c
string moo = varname(X)
strings boo = strtoarr(moo, ",")
</hansl>
in (what I hope is) obvious notation.
Yes please. I think something like this can be achieved via
strings ret = strsplit(strsub(moo,","," "))
However, I think you will have problems separating strings containing spaces. So a more
robust strtoarr() would be great!
My argument for a specific function "varnames()" was that I often need to access
a variable name (a string containing the variable name) in a loop. An array of strings
makes this easy.
Logan