Am 08.01.21 um 15:12 schrieb Allin Cottrell:
On Fri, 8 Jan 2021, Riccardo (Jack) Lucchetti wrote:

On Fri, 8 Jan 2021, Artur Tarassow wrote:

Hi,

I am not sure the following behavior of bundles and matrices data types is intended: While a foreach loop iterates over all items for bundles (items = keys) and string arrays this is _not_ the case for matrices and bundle arrays aka bundles. I think it's quite natural that it matrices and bundles should also be "iterable" but maybe I am overlooking something.

I think I remember that this distinction was agreed on during a Jitsi meeting some time ago.

"loop foreach" is intended for iterating across strings, and allowing iteration over bundle keys and arrays of strings is a special case of that. But in general "foreach" for arrays is redundant since they are indexed and ordered.

Thanks for the clarification, Allin. I agree that with your redundancy argument to some degree.

However, I've (still) have two remarks on the current behavior:

1) Using a foreach loop looks very natural (at least) to me when iterating over bundles and matrices -- even though it may be redundant :

<hansl>
bundle b = _(A = 1, B = 2)
bundles B = array(2)
B[1] = b
B[2] = b

# works
loop i=1..nelem(B)
    printf "Round %d of %d.\n", i, nelem(B)
endloop

# Not (really) supported
loop foreach i B
    printf "Round %d of %d.\n", i, nelem(B)
endloop
</hansl>


2) And this may be even more important: If the foreach type of loop is not supported for matrices and bundles, I think it should not work at all when iterating over these data types and actually throw an error. Currently, the user does not get any hint that the foreach loop runs a single round only. I was really surprised when I detected this behavior.


Best,
Artur


_______________________________________________
Gretl-devel mailing list -- gretl-devel@gretlml.univpm.it
To unsubscribe send an email to gretl-devel-le...@gretlml.univpm.it
Website: 
https://gretlml.univpm.it/postorius/lists/gretl-devel.gretlml.univpm.it/

Reply via email to