User Tools

Site Tools


gams:the_difference_between_set_and_setglobal

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
gams:the_difference_between_set_and_setglobal [2017/09/02 19:16]
support
— (current)
Line 1: Line 1:
-====== The difference between $set and $setglobal ====== 
  
-Q: I don' understand why the code below does not yield ''​yes''​ from the display.  ​ 
-<​code>​ 
-   $set cafe no 
-   ​$setglobal cafe yes 
-   ​display "​%cafe%"​ 
-</​code>​ 
-<​code>​ 
-----      3 no 
-</​code>​ 
-The reason is that the the different ''​$set'',​ ''​$setlocal''​ and ''​$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 ''​display'' ​ 
-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: 
-<​code>​ 
-   ​$setlocal cafe local 
-   ​display "​%cafe%"​ 
-   $set cafe scoped 
-   ​display "​%cafe%"​ 
-   ​$setglobal cafe global 
-   ​display "​%cafe%"​ 
-   ​$droplocal cafe 
-   ​display "​%cafe%"​ 
-   $drop cafe 
-   ​display "​%cafe%"​ 
-</​code>​ 
-<​code>​ 
-----      2 scoped 
- 
-----      4 scoped 
- 
-----      6 scoped 
- 
-----      8 global 
-</​code>​ 
- 
-Please also visit chapter Conditional Compilation in the McCarl User Guide for more information. 
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/the_difference_between_set_and_setglobal.1504372583.txt.gz ยท Last modified: 2017/09/02 19:16 by support