Re: scope of variables
- Posted by jaygade Dec 30, 2010
- 2828 views
Consistent with what? Procedures and functions are self-contained pieces of code. By enabling variables to be defined with in certain other blocks, those blocks also become self-contained pieces of code. One thing is like the other. Consistent. The only other way to make it consistent is to remove the ability to define variables in a block at all.
Maybe my original example was unclear. Here is another of what I consider to be the proper solution
integer file_log_level = log:WARNING procedure abc() integer abc = 20 -- VALID integer file_log_level = log:ERROR -- INVALID if 10 then integer def -- VALID integer abc -- INVALID end if end procedure
i.e. redefinition of any variable in any child scope is invalid. This is consistent and good practice. There is no reason to redefine file_log_level inside of a procedure or any child scope.
Jeremy
Then Euphoria should be changed to work that way I guess. I see it as less optimal but acceptable, as long as name clashes were limited to the same file and not across includes. Which I guess it wouldn't with all the different include scopes that euphoria now has.