Re: Forward reference to included function

new topic     » goto parent     » topic index » view thread      » older message » newer message
_tom said...
mattlewis said...

I think adding the new "introduce" concept makes this more confusing, because it makes it sound like where the file is included relative to use of the symbol is important. That was true in versions previous to 4.0, but is no longer true.

Matt

The location of the the include statement is important!

A variable originating in an include file will be visible, in the including file, only from the point of the include statement to the end of the file--but not anywhere before the include statement.

Not so. For example:

-- test.e 
export object foo = 1 
 
-- test.ex 
? object( foo ) 
procedure bar() 
    ? foo 
end procedure 
 
include test.e 
 
bar() 
 

Now, it's true that the variable might not have a value at the top level if it's used that way. At that point, it all depends on the order of inclusion in the program itself (i.e., has another file already included test.e?). But the variable is in scope in the including file prior to the include statement itself.

_tom said...

For a procedure or function this restriction does not apply; if you only use routines from an include file (most of the time) then you have full freedom where the include statement is written.

This is why the single term introduce is better than define and declare. Knowing where a variable is defined does not help you understand the full range of scope when there are included files. If you try to use a constant in the std/mathcons.e module and forget to include it then you get an error. If you do include std/mathcons.e the variable is only in scope from the point of introduction, that is the include statement.

The term introduce is simpler and more universal. The same description for scope applies to one file and a set of nested include files.

As demonstrated by the example, your assumptions are wrong. I think define / declare are fine, and in euphoria they are interchangeable (though it might be preferable to settle on one).

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu