From: Ethan M. <merritt@u.washington.edu> - 2004-07-08 20:12:25
|
On Thursday 08 July 2004 03:27 am, Hans-Bernhard Broeker <br...@ph...> wrote: > > > I also have some largish patches corresponding to implementations > > of several different flavors of user-accessible string variables. > > These have been discussed off and on over the last year or so, > > but I never sensed a real consensus as to which approach was > > best. > > I think that means we'll need a summary of their differences to > start off that discussion again. As far as I remember, there > were several open issues we never decided upon conclusively: I need to clean them up, modify them to apply against the current cvs source, and generally re-familiarize myself with the code. Then I'll update or replace the descriptions on SourceForge and post them to the list as well. > 1) how deep down into the expression evaluator do we put them, i.e. do > we only need string-valued variables controlled by a 'set' or 'let' > command of their own, or should 'string' become a third native type of > expression, in addition to integer and complex, meaning that we could > have string operators, string arguments and results in both internal and > user-defined functions? That would be the hard part, yes. > 3) As a follow-up to 2), how to expand variables into strings? > Bash-like $var, or C-like sprintf() style? I don't quite see how the latter would work in general. Do you mean set label 1 "After fitting, A = "+printf(A)+" B = "+ printf(B) I find that incredibly ugly and unreadable compared to set label 1 "After fitting, A = $A B = $B" Or did you mean set label 1 sprintf( "After fitting, A = %3.2f, B = %3.2f", A, B) That variant does have the virtue of allowing format specifiers. But I don't really see how either of these would work on the command line. The existing "userstrings" patch allows STYLE1 = "1:4 with lines lw 2" plot 'datafile' using $STYLE1 or even Source1 = " 'data1' using 1:4" Source2 = " 'data2' using 2:3" plot $Source1 with lines, $Source2 with points How does printf/sprintf fit in here? Admittedly the userstrings patch would probably better be described as implementing macro definitions rather string variables, but it raises the same issues of acceptable syntax. > $ already being used for at > least two entirely unrelated things in gnuplot The primary use is for column numbers. The second use I know about is for the command line variables ($1, $2, $3...). But of those are easily avoided simply by requiring that string variables start with a letter, which we would want to do anyhow to avoid parsing problems. Are there any other uses? > I would prefer the latter. I prefer $, although I have no particular objection to using some other symbol or syntax. There was an earlier suggestion to use %(VARIABLE) instead of $VARIABLE. Even so I agree that *if* we allow string functions, then some equivalents to printf() and sprintf() need to be built in. I never got as far as a solid implementation of string-valued functions in my earlier attempts, however. -- Ethan A Merritt merritt@u.washington.edu Biomolecular Structure Center Mailstop 357742 University of Washington, Seattle, WA 98195 |