Re: Forward reference to included function
- Posted by mattlewis (admin) Jan 15, 2014
- 1539 views
All identifiers must be declared which means "you pick an identifier name and state what it will be used for." In addition, the identifier has to be defined which means "you state what the identifier is or does."
I don't see the difference between declared and defined in euphoria.
- For an object (variable, constant, enum) you can declare and define the identifier on different lines or you can declare and define in one statement. The scope of the object is from the definition to the end of the source-code file.
First diagram: A variable is certainly in scope before it is assigned. You can use object(x) to test for assignment, in fact. If you try to do something else before it is assigned, you get an error about that. If it weren't in scope, then you'd get a "variable not found" sort of error.
Second diagram: This isn't quite right. A variable or constant declared anywhere in the file at top level is visible from inside a routine that is located anywhere in the file. It is only visible to code at the top level after the declaration. Likewise, inside a routine, the variable is only visible to code in the routine that comes after the declaration. Both of these are subject to the caveat that code at a higher scope level cannot see variables declared at a lower level (e.g., a variable declared within a loop is not visible outside of that loop). I may have higher/lower confused.
Matt