Am 24.10.2021 um 21:40 schrieb Allin Cottrell:
On Sun, 24 Oct 2021, Sven Schreiber wrote:
> heylist(diff(LRM)) # works!
> list oi = heylist(diff(LRM)) # fails
> </hansl>
Specifically, the second case fails with the error message:
"heylist: argument 1 is of the wrong type (is list, should be series)"
In the second case gretl notices that the statement as a whole involves
assignment to a list object. Trying to be helpful, it therefore "casts"
the argument to diff(), namely LRM, to a single-member list. This
_would_ in fact be helpful if the statement were of the simpler form
list oi = diff(LRM) # call it case B
Why? Because diff(LRM), without a cast to list for the argument,
produces an anonymous series, and only named series (members of the
dataset) can be put into lists.
Hm, thanks for the explanation...
Clearly, gretl is not clever enough here: in the heylist() context
"diff(LRM)" _should_ produce an anonymous series result; this expression
is supposed to create an argument to a function that wants a series.
Gretl doesn't understand that, unlike case B, "diff(LRM)" occurs in an
"opaque" context as an argument to heylist().
Let me just note that it wouldn't be such a big problem if in this case
diff(LRM) did produce a hardwired-prefix-named internal new series
d_LRM, I think, in analogy to what diff() does to list members. I'm just
saying it doesn't have to be anonymous, FWIW.
So what's the fix? Either (a) gretl has to figure out how to
detect
opacity of context, or (b) we drop the series-to-list cast business
altogether, in which case statements of the "case B" type would fail.
Isn't there also the option (c): cast only the _result_ of diff(LRM) to
a one-element list (with the hardwired prefix naming) in case B, instead
of casting already the argument? This would seem like the logical order
of evaluation of the statement/assignment.
Arguably, case B statements ought to fail.
Hm, if I understand correctly, the reasoning is the missing name for the
produced series result. Is that really compelling? I mean if LRM is part
of a list then there isn't a problem to apply the convention d_LRM. Why
then is it a problem to use d_LRM also if the result is a series? (Of
course, in standard assignments an explicit new name for the produced
series will be specified and so would [have to] overwrite the predefined
convention.)
if that would break any existing function packages. And if we decide
to
scrap the cast we should probably amend the doc for functions such as
diff() to point out that you can't assign to a list if the RHS is just a
series. (To be clear, it's not a problem if the RHS is a single-member
list, only if it's a series as such.)
Is that really the needed rule: "can't assign to a list if the RHS is
just a series" ? Aren't we talking about anonymous series only?
Argh, lists are nice for the simple command-like use cases, but then the
business gets messy quite quickly...
cheers
sven