From: Juergen W. <wie...@fr...> - 2008-04-08 08:47:25
|
Am Dienstag, 8. April 2008 schrieb Ethan A Merritt: > On Monday 07 April 2008 15:13, Tim Hoffmann wrote: > > Hello, > > > > because of a recent discussion on comp.graphics.apps.gnuplot I realized > > that the parsing of if ... else ... is somewhat "unusual". If the > > condition fails, gnuplot will jump to the next else (as documented). I > > don't consider this to be a good solution, because this causes troubles > > in nested if else statements. > > I think the biggest problem with gnuplot's if/else implementation is > that it is limited to a single line. The following simple construct, > if it were possible, would make the whole thing a lot more usable: > if (test) load 'option1'; else load 'option2'; > The files 'option1' and 'option2' could hold arbitrarily complex > code, partially making up for the lack of block structure. > But this doesn't work, because the command 'load' destroys the rest of > the line. Since an 'else' clase must be on the same line, but the > line is lost, you can have no 'else' clause after a 'load' command. > > So I suggest that the first step should be extending the syntax to > allow multi-line constructs. Here is one possibility: > > if (test) begin > ... > ... > else begin > ... > ... > endif > > > The 'begin' and 'endif' are not needed if the command remains on a single > line, so backwards compatibility is maintained. Sounds good. One line nested ifs should then be depricated. As soon as there are blocks, can in-file loops also be implemented? Juergen |