Credits | Overview | Plotting Styles | Commands | Terminals |
---|
The character @ is used to trigger substitution of the current value of a string variable into the command line. The text in the string variable may contain any number of lexical elements. This allows string variables to be used as command line macros. Only string constants may be expanded using this mechanism, not string-valued expressions. For example:
style1 = "lines lt 4 lw 2" style2 = "points lt 3 pt 5 ps 2" range1 = "using 1:3" range2 = "using 1:5" plot "foo" @range1 with @style1, "bar" @range2 with @style2
The line containing @ symbols is expanded on input, so that by the time it is executed the effect is identical to having typed in full
plot "foo" using 1:3 with lines lt 4 lw 2, \ "bar" using 1:5 with points lt 3 pt 5 ps 2
The function exists() may be useful in connection with macro evaluation. The following example checks that C can safely be expanded as the name of a user-defined variable:
C = "pi" if (exists(C)) print C," = ", @C
Macro expansion does not occur inside either single or double quotes. However macro expansion does occur inside backquotes.
Macro expansion is 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 will not be expanded in time
A = "c=1"; @A # will not expand to c=1
Macro expansion inside a bracketed iteration occurs before the loop is executed; i.e. @A will always act as the original value of A even if A itself is reassigned inside the loop.
For execution of complete commands the evaluate command may also be handy.