Why must references use the :: qualifier?
← Syntax and Structure Rules · Ref: Q726
EK9 uses the 'references' block to import symbols from other modules for short-name access. Each reference must use the fully qualified form: module.path::SymbolName. Using a bare name without the module qualifier triggers E01010.
REFERENCES SYNTAX
The references block appears after the module declaration:
defines module my.app references net.customer.geometry::Circle net.customer.geometry::Pi
The '::' separator divides the module path (left) from the symbol name (right).
FULLY QUALIFIED INLINE
You can also use fully qualified names inline without a references block:
circle <- net.customer.geometry::Circle(5.0)
This works anywhere but is verbose for repeated use.
AFTER IMPORTING
Once referenced, use the short name directly:
references net.customer.geometry::Circle defines program Demo() c <- Circle(5.0)
ALPHABETICAL ORDER
References must be listed in alphabetical order (E11026).
MULTI-FILE WORKSPACE
This Q&A demonstrates cross-module references: the referenced module (qa.syntaxrules.refsupport) is defined in a separate companion file, just as it would be in a real EK9 project.
See Q6 for module organization. See Q142 for cross-module constants.
Example
defines module qa.syntaxrules.modulereference references qa.syntaxrules.refsupport::Formatter qa.syntaxrules.refsupport::MaxItems defines program ModuleReferenceDemo() stdout <- Stdout() //Short name access via references block formatted <- Formatter("hello") stdout.println(formatted) stdout.println(`Max items: ${MaxItems}`) //Fully qualified inline access also works formatted2 <- qa.syntaxrules.refsupport::Formatter("world") stdout.println(formatted2)
Companion: QA0726_referenced_module.ek9
#!ek9 defines module qa.syntaxrules.refsupport defines constant MaxItems <- 50 defines function Formatter() as pure -> text as String <- rtn as String: `[${text}]` //EOF
Other ways to ask this
- What is E01010 invalid symbol by reference?
- How do I import a type from another module in EK9?
- What is the correct syntax for EK9 references?
Coming from another language?
Java: import com.example.MyClass with dot-separated path. Python: from module import Class. Go: import path/package. Rust: use crate::module::Type. C#: using Namespace.Type. EK9: references block with module.path::SymbolName using :: separator.
Keywords: cross, access, symbol, module, E01010, syntax, reference, qualifier, import