From: Ethan A M. <merritt@u.washington.edu> - 2004-07-18 06:32:01
|
On Saturday 17 July 2004 10:00 am, Hans-Bernhard Broeker wrote: > > The problem is that %l/%L and similar formats must always be used in > pairs, and the code needs to know which the pairs are: the rounding on the > %l part affects what the right result on %L is. The number 9.999 can come > out as 9.999*10^0 or 10.0*10^^1. > > The two of them could be called gprintf and sprintf or similar. I have posted a 2nd patch, stringvars-2, to SourceForge. stringvars-1 and stringvars-2 are to be applied sequentially. This one adds run-time evaluation of all quoted strings beginning "sprintf... that are printed via write_multiline(). It turned out to be amazingly easy. I am very impressed with the existing implementation of expression evaluation; slotting in evaluation of string-valued functions "just worked". Here's a neat example that demonstrates plot-time evaluation: set title 'sprintf("Plotted at %s",`date`)' plot <something> pause 3 "Should show new time" replot pause 3 "Should show new time" replot NB: The specific placement of single and double quotes is critical for this to work. See my recent bug report about gnuplot losing the single-quoted-ness of strings after their initial evaluation. This example currently works by accident, but I think we should re-examine how quoted strings are stored in general. Anyhow, adding additional string-valued functions would be very easy. Let's discuss which ones might be desirable. 1) gprintf("format",mantissa,exponent) Is that the form it should take? 2) Some way to do arithmetic using numerical values stored in a string. E.g. a = "1.2" b = 3.4 c = a+b It would be straightforward, although tedious, to modify every existing atomic evaluation routine in internal.c so that it recognizes string-values during arithmetic. They would be converted to (double) using atof(). But is this at all necessary? Maybe it is sufficient to simply provide a built-in atof() function. Or maybe we don't even need that. 3) user-defined string-valued functions. I don't see at the moment how to implement these, although I think it would be possible. Are they needed? 4) Do we want any string operations besides concatenation? Substrings? String comparison? -- Ethan A Merritt Department of Biochemistry & Biomolecular Structure Center University of Washington, Seattle |