Re: goto / global variables
- Posted by Robert Craig <rds at CLASSIC.MSN.COM> Sep 28, 1997
- 968 views
Daniel Berstein writes: > --This is file MODULE.E > static myvar > global function read_myvar() > return myvar > end function > global procedure write_myvar(atom value) > myvar = value > end procedure > -- End file > > -- This is file PROGRAM.EX > atom test_value > write_myvar(100) --Now myvar holds the value '100' > test_value = read_myvar() --test_value > write_myvar(test_value*2) --Nowmyvar holds value '200' > myvar = 100 --Error! you can't reach myvar directly > --End file Your proposed "static" keyword is unnecessary because "static" is the *default* in Euphoria. All symbols are "static" unless they are declared with "global" in front of their declaration. For a symbol to be accessible from another file you *must* declare it as "global". In C/C++ all symbols are potentially accessible from any other source file unless you declare them as "static". In Euphoria it is the opposite - symbols are *not* accessible unless you say "global". I recently read an article by Bjarne Stroustrup, the guy who created C++. Among other flaws in C, he pointed out that the default should have been "static", (i.e. it should have been done the way Euphoria does it). Regards, Rob Craig Rapid Deployment Software