Am 13.02.2018 um 18:33 schrieb Allin Cottrell:
On Tue, 13 Feb 2018, Sven Schreiber wrote:
> catch scalar sc = sum(1) # error: "data types not
matched"
> catch scalar sc = sum(djclose) # OK
> catch scalar sc = sum(1) # error: "sc is scalar, not acceptable"
> </hansl>
First a very minor comment: Isn't it strange that the same lines (1 & 3)
result in two different error messages?
sum() accepts a series, matrix or list argument. You can never refer
to
series as such by ID number in gretl functions, only in commands.
Ah, OK.
However, "1" is a valid constructor for a list so
that's how it's
interpreted, and under that interpretation the output is correct,
according to the documentation.
I understand.
If there's a bug here, it would be accepting "1" as
defining a
single-member list in the context of a function argument. Maybe
functions should accept only named lists, and an argument of "1" for
sum() should be flagged as a type error.
First I thought "why change something that's working?", but then I
thought more about anonymous on-the-fly lists in this context, consider
the following:
<hansl>
open denmark
list mylist = 1
eval sum(mylist) # series itself (trivial cross-sum)
eval sum(1) # ditto
eval sum({1}) # gives 1
mylist = {1, 2}
eval sum(mylist) # gives a sum series
eval sum({1, 2}) # gives 3
mylist = 1 2 # works
eval sum(1 2) # doesn't work (as expected)
</hansl>
If a function accepts an anonymous single-member list declared by ID
such as '1', then it should also accept a more general ID definition.
But AFAICS that's not possible in hansl, because of the clash with a
standard matrix. (See the "gives 1" and "gives 3" lines above.)
So yes, it now seems to me the cleanest solution is to ban such weird
(at least to me) anonymous list constructs there!
Then this would also be consistent with your rule above about series IDs
in functions.
Jack, take note, I'm in favor of a backwards-incompatible change...
cheers,
sven