|
From: sfeam <sf...@us...> - 2017-10-08 17:49:54
|
On Sunday, 08 October 2017 13:32:04 Achim Gratz wrote:
>
> Is there some description how the variable scoping is supposed to work
> in blocks? It seems that they will need to be defined outside the block
> in order to be visible beyond the block and any set operations inside
> the block will be nixed when that block is left?
With one exception, gnuplot variables are global.
There is a single, persistent, list of active variables indexed by name.
Assignment to a variable creates or replaces an entry in that list.
The only way to remove a variable from that list is the "undefine" command.
The one exception is the controlling variable of an iteration.
In that case the scope of the variable name is the iteration itself.
A previous instance of that variable name, if any, is saved at the
start of the iteration and restored at the end
Example:
j = "foo"
do for [j=1:3] {
plot for [j=5:6] x*j title "plot x*".j
}
print "j =", j # will report j = "foo"
Re-use of the name "j" in the do loop shadows the global
variable of that name, and re-use in the plot statement
shadows both of the outer uses.
Block structure is not relevant per se except that one use of a
block is to delineate the content of an iteration.
Ethan
>
>
> Regards,
> Achim.
>
|