|
From: Philipp K. J. <ja...@ie...> - 2009-11-11 03:22:57
|
On Tuesday 10 November 2009 07:10:51 pm you wrote: > On Tuesday 10 November 2009, Philipp K. Janert wrote: > > > > Since 4.0 we support string variables. That means wherever a string > > > > is required in the input command, it is acceptable to provide > > > > a string constant, a string variable, or a string-valued function. > > > > Although there is still a confusion: you write > > "where a string is required" > > > > In this example, no string is required. > > Of course a string is required. It is going to become the > first N characters of a longer string. How could it be anything > other than a string itself? It's not a string as far as the gnuplot session is concerned. Here: plot "file" using 1:2 In this example, "file" is a string within the gnuplot session. But using is not a string in the same way - it's a keyword. Similarly: a = 1 Here, a is not a string within the gnuplot session. It's a variable name. In the same way, our prefix is not a string within the gnuplot session. It's an (unquoted) bareword. The best way to see this is that there is no need to quote it and any quotes are not stripped out. (This is a totally different question whether any of this is IMPLEMENTED as a C string. Of course it is. But that's not what I am talking about.) > > > A bareword > > is required. It is your assumption that it should be > > a string. (And it is now a discussion item whether > > it should be a string - in which case the string needs > > to be handled properly, admittedly.) > > > > > > So > > > > A = "mydata" > > > > stats "file.dat" using 1 variable=A > > > > > > > > must expand A to find "mydata", not use it as an unmarked constant. > > > > All strings should be parsed using the routine try_to_get_string(), > > > > which handles the three cases. > > > > Also, normal commands do not use = signs. > > > > > > Good point on the string variable issue - I did not > > > think of that. > > > > > > There is a reason for the equality sign, though: > > > it indicates that the next token is the prefix - > > > because we have chosen to make the prefix > > > optional. The equality sign is a way of telling > > > gnuplot that the next token is a prefix, not the > > > next keyword. > > Not following you here. > The keyword itself can be optional - you don't have to provide a prefix. Ha! But : stats "file" and stats "file" var have different behavior! In the first case, no assignment to variables is made. Only in the second do we assign to variables. (Without a prefix.) So, how do I distinguish without the equality sign (or another keyword) between: stats "file" var noout and stats "file" var foo Here, the first is supposed to assign to variables and not print to screen (keyword "noout"), whereas the former assigns to variables with prefix foo, but does not print to screen? To distinguish these cases, I need to tell gnuplot that the foo in the second cases "belongs to" var. The simplest way I could think of was to use the equality sign. > But if you include the keyword in your command, then the next token > must be a string. Where does the = sign come in? > > [maybe "prefix" is a better keyword than "variable"] > > > > (I admit that the equality sign is unusual and I did > > > hesitate a little. But it does provide a simple solution > > > to this particular problem.) > > > > > > I don't want to make the prefix mandatory. For > > > convenience, it seems that in many cases it won't > > > be needed. > > So let it default to an empty string. |