Mutual Inclusion

Mutual Includes

Consider two files A and B. It is possible for A to include B, making A the "primary" and B the "module." It is equally valid for B to include A, making B the "primary" and A the "module." Sometimes the rules for scope have to be applied twice in order to understand how scope is formed.

Mutual inclusion occurs when two files include each other in order to share identifiers between the two files.

When you create a large program out of many smaller included files:

  • No individual file has special properties . No file has special syntax that makes it the main, a primary, or a module file. ( Using .ex and .e file extensions is just a typing convention.)
  • Any two files can be considered to be a primary:module pair
    and these same two files can equally be considered to be a module:primary pair.

Two Modules with Mutual Inclusion

Consider three files. The main program myapp.ex includes one module file foo.e . This example illustrates mutual inclusion between two module files; notice that the two "module" files have to include each other for this example to work. The primary file foo.e includes the module bar.e , and the primary file bar.e includes the module foo.e .

Examine the relationship between bar.e and foo.e . The procedure showit needs a variable that is declared in foo.e . Therefore foo.e must be included as a module and Foo must be declared with a scope modifier:

Examine the relationship between foo.e and bar.e . The procedure showit is called in the file foo.e . Therefore bar.e must be included as a module and showit must be declared with a scope modifier:

When you launch eui myapp.ex this example works as planned. Notice that eui foo.e works correctly, but that eui bar.e crashes with an error message.

The syntax rules describing scope between two files has symmetry because Euphoria is designed to be simple.

The resulting scope between any two files is usually different. Identifiers that are exposed in a primary:module relationship do so in one direction only. Do not expect the scope between any two files to be mirror images of each other. No identifier appears (or disappears) by surprise in Euphoria; you always control the scope of any identifier using a declaration statement, scope modifiers when declaring, and include or public include statements.


Quick Links

User menu

Not signed in.

Misc Menu