|
From: m s. <mw...@us...> - 2008-11-09 22:31:24
|
> ----- Original Message ----- > From: "Ethan A Merritt" <merritt@u.washington.edu> > To: gnu...@li... > Cc: "m sutton" <mw...@us...> > Subject: Re: expanding allowed usage of word() command > Date: Sun, 9 Nov 2008 11:56:03 -0700 > > 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. I think I over simplified my initial example. I have been working to convert a program that plots model outputs using XGKS. Gnuplot creates nicer looking plots and can generate PNG and other formats that can be put directly into documents and presentations. I have been able to do most every thing so far. The user specifies non-gnuplot commands that can result in either lines or points being plotted. It was not until the "for" iteration was added to Gnuplot that the conversion to Gnuplot became feasible. I currently have been hacking the plotting of points using empty string labels with points. One down side is that zooming doesn't crop out labels. So the Gnuplot command I was striving for would look like this. n=3 list="lines lines points" ls_list="3 6 99" plot for [j=0:n] 'data.dat' index j with word(list,j+1) ls word(ls_list,j+1) I figured since word() gets evaluated for the "linestyle" portion it might get expanded for the "with" portion too. I can understand the hesitation to allow something other than a keyword after a "with". The "set style line" mechanism doesn't let you specify that lines or points be used. So would it be less hackish to change lines styles so that 'set style line' can some how specify that lines or points be used. Or should the word() function be allowed to dynamically substitute keywords? Perhaps some combined thought power can arrive at a solution. Mike Sutton -- Be Yourself @ mail.com! Choose From 200+ Email Addresses Get a Free Account at www.mail.com |