If an in-line sampling range is given within a "plot for []" loop, no definition can be added before the function to be plotted:
gnuplot> plot [0:10] for [i=0:9] [i:i+1] a=1 i+a w p
^
unexpected or unrecognized token
the parser seems to think "a=1" already is the function.
The documentation was not quite right. It should say (and now does):
In other words, your plot command will work if it is written as
plot [0:10] for [i=0:9] a=1 [i:i+1] i+a with points
The sampling range must come immediately before the function it modifies.
Last edit: Ethan Merritt 2014-08-25
Ah, OK. This however turns up a similar problem like the one we recently discussed on the newsgroup (function starting with bracket gets mistaken as function call in a previous definition):
gives "internal error: substring range operator applied to non-STRING type". Parser holds the last pair of rectangular brackets to be a string operator on "i", one can get it to work by ending the definition clause with a number:
Last edit: Karl Ratzsch 2014-08-26
I guess this cannot be resolved without a major change in the synax, so we´ll just have to go with it?
Patch adds an explanation to the help on "plot for []" (i reorganised that page a bit, too).
I'm still not clear on what you are trying to achieve. Every example so far has been a case of adding a definition to the plot statement that is totally unnecessary, in the sense that it could just have well have been defined beforehand outside of the plot statment.
Can you give an example that would actually require placing a definition in the plot statement itself? Otherwise I am inclined to say that the resolution of the problem is simply not to put definitions inside a plot statement, just as I also recommend not to put axis ranges in a plot statement. The syntax was originally designed to allow both of these, but IMHO that was a mistake.
Agreed, I think there is no "hard" need to do a definition inside the loop, one could always do it inside the function call, e.g. instead of
do
It just (here) saves calling af(i) a second time.
But as it is explicitly allowed, I thought it should be foolproof to use, or the possible hooks should at least be documented.
However, the superior solution might indeed be to remove the possibility to make definitions inside the loop. At least that´d be an easier decision than removing inline axis ranges. They´re ugly, but have been used since forever and are just so damn convienient, lazywise. ;-)