On Tue, 13 Feb 2018, Sven Schreiber wrote:
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?
I can see why the message might be different: on line 1 there's no
object by the name "sc" and it's merely an aspiration to assign a
series result to a scalar. On line 3 we already have a scalar object
"sc" in good standing -- created on line 2 -- but such an object is
not acceptable on the left-hand side of the assignment. However, I
don't really like the second error message, and it's on my (long)
agenda to try to replace both messages with something like "You
cannot assign a series result to a scalar".
[...]
> 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.
Ah (remembers something), I think the rationale for this sort of
contortion has to do with lists in bundles. Consider:
<hansl>
open data4-10
list L = 1
bundle b = defbundle("L", L)
eval sum(b.L)
</hansl>
The thing is that b.L is not a named list but an anonymous object
holding the value "1". Can we allow the case above while banning
sum(1)? I'm not sure, but it's probably worth experimenting.
Allin