|
From: Arun P. <ape...@lb...> - 2011-04-01 04:09:25
|
Hi
On 03/31/2011 07:50 PM, sfeam (Ethan Merritt) wrote:
>[...]
> The macro mechanism was a first attempt at string handling.
> It didn't really work out all that well.
> Proper string handling replaced it for most purposes,
is there a way then that I can do things like
set macros
f(s)=sprintf("m=%s_m",s)
g(x)=m*x
t1_m = 1.0
t2_m = 2.0
A=f("t1")
B=f("t2")
plot @A,g(x),@B,g(x)
without using macros?
> and perhaps
> the macro stuff should have been removed, but we're such sticklers
> for backwards compatibility that it's still there.
>
> Anyhow...
> The problem you're seeing is inherent in the way that the macros work.
> They are applied line-by-line to the input stream, as the very first
> thing before the line is actually interpreted or executed.
> But that means if you define a new macro on a particular line,
> that line has already been through the macro substitution process
> and substitutions involving the new macro cannot take effect until
> the next line.
Thanks for the explanation, makes sense...
Here is some addition for the manual (output of cvs diff -u)
-----------------start-------------------------------
RCS file: /cvsroot/gnuplot/gnuplot/docs/gnuplot.doc,v
retrieving revision 1.658
diff -u -r1.658 gnuplot.doc
--- gnuplot.doc 26 Mar 2011 02:39:44 -0000 1.658
+++ gnuplot.doc 1 Apr 2011 04:07:32 -0000
@@ -2584,6 +2584,18 @@
Macro expansion does not occur inside either single or double quotes.
However macro expansion does occur inside backquotes.
+ Macro expansion is also handled as the very first thing the
+ interpreter does when looking at a new line of commands and is only
+ done once. Therefore, code like the following will execute correctly:
+
+ A = "c=1"
+ @A
+
+ but this line will not, since the macro is defined on the same line
+ and can't be expanded in time
+
+ A = "c=1"; @A # will not expand to c=1
+
For execution of complete commands the `evaluate` command may also be
handy.
3 String variables, macros, and command line substitution
?mixing_macros_backquotes
-------------------end----------------------
Thanks for the quick help
Arun
|