Question

How can I avoid name conflicts among modules? From the documentation, it seems currently there is no principled name management among modules in Rascal. When importing a module, all names declared public in the imported module come into scope. Is there a way for qualified import? Or will there be?

Was it helpful?

Solution

Good question again :-) The short answer is you qualify the names at the use sites in the module that has imported the same name twice.

The long answer is three-fold:

  1. The extend mechanism (as opposed to import) will support renaming at extension time in the future.
  2. When two names clash, in the sense that there is an ambiguity due to importing two modules that use the same name, the name is to be qualified at the use site in the current module. The type checker will suggest something appropriate (when it is released).
    • For example in this ambiguous code: int a = f; (imagine f was imported from both module A and module B), you should write: int a = A::f or int a = B::f to resolve the ambiguity.
  3. For non-overlapping functions, algebraic data-types and syntax non-terminals clashes do not exist, they are merged.
    • For example: data A = a(); from one module is merged with data A = b(), same for syntax syntax Exp = Exp "+" Exp; is merged with syntax Exp = Exp "*" Exp; and for functions: int f(int i) = 1; is merged with int f(real r) = 1;.
    • On that note, you could still refer to one of the alternatives using: A::f(1) to prevent using the merged version.
    • And overlapping functions will still require disambiguation, when the parameter patterns are not mutually exclusive (an example would be: int f(int i) = 1; from one module with int f(value x) = 2; from another.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top