Am 17.05.2015 um 02:37 schrieb Allin Cottrell:
On Sat, 16 May 2015, Sven Schreiber wrote:
>
> <hansl>
> matrices mc
> mc += ones(3,2) # += refers to whole array
> mc[1] += ones(3,2) # += should refer to 1st array element
> </hansl>
Gretl is not so much confused as just incompetent ;-) It kinda "knows"
what you're trying to do, but doesn't support it, yet.
One more fundamental comment about the syntax: in hansl appending to a
matrix or to a string works with the "~" operator (or ~=). Here in the
array context appending is done with "+" or "+=". I'm not sure
this is
wise or intuitive. Admittedly, appending to a list is also done with
"+=", but instead of "+" with lists there is no operator in
expressions
like 'list mylist = oldlist1 oldlist2'. Perhaps it's time to sort this
all out, for example by allowing "~" as an additional alias whenever an
action of appending is involved.
OTOH, I can see that while this would make it easier to implement "+="
for a matrix inside an array, it could complicate to do "~=" for a
string inside an array (which currently does not work, either).
...
If (something like) the above is legal, that means that mc must already
be defined as an array of matrices, so there's no call to prefix the
assignment with a type-word;
mc[1] = ones(3,2)
will do the job fine.
Yes I know and that's what I'm (necessarily) doing. However, I think
it's good style to always use the type specifier (matrix, string,
series, list, ...) to be explicit. Personally I only omit this for plain
scalars.
BTW, I found a new bug while pondering this, with bundles. Example:
<hansl>
nulldata 10
bundle bc
# standard way to get a constant series
series sconst = 5
# try to create a constant series in the bundle
series bc.sconst2 = 5
# but produces a scalar!
string type = typestr(inbundle(bc, "sconst2"))
print type # gives "scalar"
</hansl>
Actually I was surprised that "series bc.sconst2 = 5" doesn't trigger an
error in the same way as with arrays.
(I know I can do "bc.sconst2 = sconst" to get the desired result, that's
not the point. The point is how to specify the types of bundle elements
unambiguously[, without workarounds].)
thanks,
sven