|
From:
<br...@ph...> - 2005-06-28 17:28:37
|
Ethan A Merritt wrote:
> The difficult case (which this is not an example of) is
> distinguishing a user-defined function that returns the name of a
> file from a user- defined function that returns a numerical value.
We may be closer to that case than you realize.
plot fdat
could be a plot of a file (if fdat is a string-valued variable), a
linear function (if 'set dummy fdat' is in effect), or a constant (if
fdat is a numerical variable). There are four cases, distinguished by
the attribute pairs string<-->numeric and literal<-->expression.
There is not actually a distinction between function and expression to
be made here. I.e. the 'plot' command line parser is not trying to find
a function --- it's trying to find an expression that it can evaluate,
and a simple variable or even a literal fit that bill nicely. That's why
all of
plot 5
plot a
plot x
plot 5*a+f(x)
work. To recognize that a file name is being input, the parser needs
some way of figuring out that what the type of a given expression is.
Before string variables, that was simple: strings could only be
literals, and those were easy to recognize by the opening ' or ". Now
it's trickier, and in the example discussed here, it fails.
In the case of a 'plot fdat', there's no syntactic hint at all --- you
have to actually check the type of fdat to see if this is a filename or
a numeric variable. I.e. the exact same plot command line could produce
a function or a data plot, at different times in the same gnuplot session.
|