On Mon, 24 Sep 2018, Sven Schreiber wrote:
OK here's something a little embarassing, because there's a
syntax mistake on my part. However, it's interesting that gretl didn't
complain about the syntax error, only afterwards:
loop i = 1 to 5 # of course wrong syntax, instead of 1..5
print i # complaint happens here
I wonder how gretl interpreted that "1 to 5" part...
Hmm, gretl is trying to treat this as a "count" loop, with the string
"i = 1 to 5" as a candidate expression for producing the number of
iterations on evaluation. This is, I notice, an undocumented extension
of the count loop syntax (the doc says the number of iters should be a
numeric constant or the name of a scalar variable).
Anyway, evaluation of "i = 1 to 5" then fails since (first error) "i"
is undefined -- and that's actually the source of the error message,
not the attempt to print i.
What should we do? It would be easy to enforce the documented count
loop syntax -- and therefore flag a syntax error up-front in this
case. But I wonder if there's any usage of the extended count-loop
syntax out there among extant hansl scripts. The sort of thing one
might reasonably expect to work (even though it's contrary to doc)
would be, "loop K/2", "loop N-M" and such.