|
From: Ethan A M. <merritt@u.washington.edu> - 2008-11-09 18:56:17
|
On Sunday 09 November 2008, m sutton wrote:
>
> > ----- Original Message -----
> > From: "Ethan A Merritt" <merritt@u.washington.edu>
> > To: gnu...@li...
> > Cc: "m sutton" <mw...@us...>, "Hans-Bernhard Bröker" <HBB...@t-...>
> > Subject: Re: expanding allowed usage of word() command
> > Date: Sat, 8 Nov 2008 09:30:53 -0700
> >
> >
> > On Saturday 08 November 2008, m sutton wrote:
> > > Hi all,
> > >
> > > I was trying to plot a single data file with multiple indexes. I
> > > want to plot some indexes with lines and some with points. I
> > > tried the following in a 4.3 CVS snapshot:
> > >
> > > list="points lines points"
> > > plot for [j=1:3] 'data' with word(list,j)
> > >
> > > I thought the word() command would be expanded much like it does
> > > for title. However it just results in an expecting error.
> > >
> > > Should the word() command be expanded in the above situation? If
> > > so, would that be difficult to implement?
> >
> > There is still a fundamental difference between a keyword and
> > a string value. Your failed command did get expanded, but the
> > expanded form is equivalent to
> > plot 'data' with "points", '' with "lines", ...
> >
> > which isn't a legal command.
>
>
> I put a few print statements in the code to see what was happening. I added a print statement to f_words to see when the function was being called. And to lookup_table to see what the current token was. I change the commands to the following to force a call to f_words. An the result shows that f_words is not called during the plot command call.
>
> list="foo bar"
> print "word 1 = ". word(list,1)
> plot for [j=1:2] x with word(list,j)
>
>
> The results was the following
>
> gnuplot> list="foo bar"
> gnuplot> print "word 1 = ". word(list,1)
> enter f_words
> word 1 = foo
> gnuplot> plot for [j=1:2] x with word(list,j)
> token = word
> ^
> expecting 'lines', 'points', 'linespoints', 'dots', 'impulses',
> 'yerrorbars', 'xerrorbars', 'xyerrorbars', 'steps', 'fsteps',
> 'histeps', 'filledcurves', 'boxes', 'boxerrorbars', 'boxxyerrorbars',
> 'vectors', 'financebars', 'candlesticks', 'errorlines', 'xerrorlines',
> 'yerrorlines', 'xyerrorlines', 'pm3d', 'labels', 'histograms',
> 'image', 'rgbimage'
>
>
> I guess the real question is should the word() command be allowed to specify the with type?
You are asking for substitution of keywords, which is a somewhat different
process than the evaluation of string-valued functions. There actually is
an existing mechanism for macro-substitution, although it hasn't been
re-examined in the context of iteration clauses.
I think the command you are aiming for is
set macros
plot for [style in "lines impulses"] foo with @style title style
That almost works. Note that the clause
with @style title style
expands the same user variable 'style' using two different mechanisms.
'title style' uses it as a string constant.
The macro @style is exanded to generate a string of lexical
tokens, which means that a keyword is an acceptable value.
The command as shown currently fails because the process of macro exansion
overwrites the original command line rather than preserving it.
That works fine for a one-shot use, but breaks when the command line is
re-scanned for iterative execution. That may be fixable.
Bottom line:
1) It may be possible to do as you say, and add a special case to the
parser so that if it fails to find a keyword after "with" it falls
back to attempting evaluation of a string-valued function that returns
a keyword. This strikes me as very hack-ish and ugly, but perhaps we
can come up with a less hackish or more general form.
2) Alternatively, the macro expansion code can be updated to work
inside an iteration loop.
I view the macro-expansion mechanism in gnuplot as being kind of a
failed experiment. It was an early attempt to work around the lack of
string variables. Now that gnuplot supports both string variables and
string-valued functions, there is not much need for the macro mechanism.
But this may be a case where it really would make sense to use it.
--
Ethan A Merritt
|