Q: I don' understand why the code below does not yield
yes from the display.
$set cafe no $setglobal cafe yes display "%cafe%"
---- 3 no
The reason is that the the different
$setglobal commands do
not reference the same variable. They create different variables at different
levels of scope. When a variable is referenced (for example by a
statement) is determined by the scoping rules. If there is a local variable by
that name that's what you'll get. Otherwise you'll get a viable defined at a
higher scope level. You'll see the global variable only if there isn't anything
at a lower scope level hiding it.
The example below demonstrates how things work:
$setlocal cafe local display "%cafe%" $set cafe scoped display "%cafe%" $setglobal cafe global display "%cafe%" $droplocal cafe display "%cafe%" $drop cafe display "%cafe%"
---- 2 scoped ---- 4 scoped ---- 6 scoped ---- 8 global
Please also visit chapter Conditional Compilation in the McCarl User Guide for more information.