manpagez: man pages & more
info gnuplot
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.22.2 Substitution of string variables as macros

Substitution of command line macros is disabled by default, but may be enabled using the macros command. If macro substitution is enabled, 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:

      set macros
      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

For execution of complete commands the evaluate command may also be handy.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on April 4, 2012 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.