On Sun, 24 Oct 2021, Sven Schreiber wrote:
<hansl>
function list heylist (const series x)
print "aha"
list out = x
return out
end function
open denmark
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.
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().
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.
Arguably, case B statements ought to fail. But we probably need to
check 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.)
Allin