|
From: Ethan A M. <sf...@us...> - 2012-05-03 21:07:50
|
Tait <gnu...@t4...> wrote >
> > So yes, there is an inconsistency. There are currently three "for"
> > constructs
> > do for
> > set for
> > plot for
> >
> > The first two of these always iterate at least once; the third one does not.
> > The documentation is silent on the intended behavior.
> > So which to change, "plot for" or both the others?
>
> Given that it's called "for" I'd say the principle of least surprise
> dictate that it act consistently with "for" as used in most programming
> languages (e.g. C).
Well, C doesn't really have an automatic iterator of this form; you have to
provide an explicit initialization, an explicit while condition, and an
explicit iteration operation.
It turns out to be surprisingly hard to determine what
"most programming languages" do. Many require an explicit increment
operation, like C.
FWIW, here is what you get in R, whose syntax is close to that of gnuplot.
R> for (i in 4:1) { print(i) }
[1] 4
[1] 3
[1] 2
[1] 1
So that's a third option to consider.
It's not too late to consider adopting this behavior for gnuplot also:
for [i = start : end {: increment}]
where increment defaults to -1 if (start > end) and +1 otherwise.
Ethan
|