3.1. The open directive

It's really boring writing qualified names all the time. Felix provides the open directive to allow you to open a module so its contents can be accessed without using qualified names. Here's a simple example:
Start felix section to tut/tutorial/tut-2.01-0.flx[1 /1 ]
     1: #line 4956 "./lpsrc/flx_tutorial.pak"
     2: //Check open directive
     3: #import <flx.flxh>
     4: module X {
     5:   proc print_endl (a:int) { print a; endl; }
     6:   fun square (a:int):int = { return a * a; }
     7: }
     8: 
     9: open X;
    10: print_endl (square 2);
End felix section to tut/tutorial/tut-2.01-0.flx[1]
Start data section to tut/tutorial/tut-2.01-0.expect[1 /1 ]
     1: 4
End data section to tut/tutorial/tut-2.01-0.expect[1]
Note that the open directive only affects lookup of unqualified names, or the first component of a qualified name. Lookup proceeds first in the current scope, before considering opened modules; then opened modules are considered, then the parent scope, then opened modules in the parent, etc.

The name of the module to be opened is not looked up in the modules opened by open directives in the same module as itself. Open directives in containing modules are, however, examined.

The reason for this last rule is as follows: open directives, like Felix declarations, are all considered in parallel; that is, their order of writing is irrelevant; hence, open directives are considered in a context in which none of the open directives have been applied.

It is not an error to open modules containing conflicting definitions, however, it is an error to refer to a name with conflicting definitions.

Functions with the same name in opened modules are overloaded. If two functions have the same signature, a reference will lead to an ambiguity. Such an ambiguity can be resolved by hiding such definitions in opened modules by providing a definition in the module containing the open directives. Alternatively, you can use a qualified name.

Start felix section to tut/tutorial/tut-2.01-1.flx[1 /1 ]
     1: #line 5007 "./lpsrc/flx_tutorial.pak"
     2: //Check open directive
     3: #import <flx.flxh>
     4: module X1 {
     5:   proc printme() { print "X1"; endl; }
     6: }
     7: module X2 {
     8:   proc printme() { print "X2"; endl; }
     9: }
    10: open X1;
    11: open X2;
    12: proc printme() { print "top level"; endl; }
    13: 
    14: X1::printme();
    15: X2::printme();
    16: printme();
End felix section to tut/tutorial/tut-2.01-1.flx[1]
Start data section to tut/tutorial/tut-2.01-1.expect[1 /1 ]
     1: X1
     2: X2
     3: top level
End data section to tut/tutorial/tut-2.01-1.expect[1]
Finally note that the effect of opening a module named X which contains an entity named X is well defined: the contained X will not be seen by other open directives, whereas the module X will not be seen by any declarations and definitions in the body of the containing scope.