Many thanks!
I used exists and nelem... because the exists doesn't matter yet but might in future.
Anyway, there are other bugs. I wasn't aware of the forach problem. Thanks!
(And there are still other bugs in my code example...)
Frederik
-----Ursprüngliche Nachricht-----
Von: gretl-users-bounces(a)lists.wfu.edu [mailto:gretl-users-
bounces(a)lists.wfu.edu] Im Auftrag von Sven Schreiber
Gesendet: Freitag, 5. Januar 2018 14:17
An: gretl-users(a)lists.wfu.edu
Betreff: Re: [Gretl-users] passing list to function, loop
Am 05.01.2018 um 14:07 schrieb Schaff, Frederik:
> list seems to pass the names of the series, but does not work. If I
> remove the function body, everything works.
Yes, see the "Foreach loop" section in the loop chapter 12 of the manual:
"Note that if you use this idiom inside a function (see chapter 13), looping
across a list that has been supplied to the function as an argument, it is
necessary to use the syntax listname.$i to reference the list-member
variables."
(Of course, $i must be replaced with what the loop index is in your case.)
> function matrix MatOrderDist (list ls, list lsB[null])
> if exists(lsB)
Hey, we had this before, don't use exists() with list function args. It will
always return 1, even for null. Use nelem() directly (with lists only!).
> loop foreach item ls -q
> to_plot[r,1] = min($item)
OK, this would need to be ls.$item instead.
> loop foreach item lsB -q
> to_plot[r+offset*(r-1),1] = min($item)
And this: lsB.$item.
hth,
sven
_______________________________________________
Gretl-users mailing list
Gretl-users(a)lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-users