Using..Do
| Release: |
• 4.6 • 5.0 • 5.1 • 5.2 • 5.3 • 5.4 • • 6.0 • 6.1 • 6.2 • 6.3 • 6.4 • 6.5 • 6.6 • 7.0 • 7.1 |
|---|
Using «NS» Do «expr» evaluates «expr» with the public identifiers of namespace «NS» brought into scope. Within «expr», an unqualified identifier that does not resolve in the normal scope is then looked up inside «NS» — the same lookup that the NS::Identifier qualifier performs. «NS» must itself be a namespace (a system library, or a Module with NamespaceDefaultScope set); it may be qualified, e.g. A::B.
Syntax
Using «NS» Do «expr»Using «NS»; «rest-of-block»
The Do «expr» form scopes the inclusion to a single expression. The ; form (no Do) scopes it to the rest of the enclosing block — typically the rest of the Definition or Local … Do body.
The keyword Namespace may optionally appear between Using and «NS» for readability:
Using Namespace «NS» Do «expr»Using Namespace «NS»; «rest-of-block»
Motivation
The intended use is occasional access to a single member of a namespace that you don't want to import into your model's NamespaceImports permanently. For example, to call the experimental CefWindow function without importing all of SysLib_Experimental:
Using SysLib_Experimental Do CefWindow( ... )
evaluates the same as
SysLib_Experimental::CefWindow( ... )
with one practical advantage: if CefWindow is later promoted out of the experimental library (becomes an official top-level function), the Using form continues to work unchanged, while every fully-qualified call site would have to be edited.
Resolution rules
- Locally declared names (parameters,
Local,Foriterators) and names already visible in the current scope take precedence over names brought in byUsing.Usingonly fills in identifiers that normal lookup couldn't find. - When two
Usingdeclarations are nested and both namespaces define the same identifier, the innermost one wins. There is no ambiguity error — resolution is deterministic. - The included namespace is a parse-time-only scope; it has no runtime cost.
- «NS» must resolve to a namespace. Pointing
Usingat a variable or non-namespace module raises the error «X» is not a namespace. The Using declaration requires a namespace identifier.
Compatibility with earlier releases
In Analytica 7.0 and earlier, Using «x» := «expr» was a deprecated alternate spelling of Local «x» := «expr». As of Analytica 7.1 the Using keyword has been repurposed for namespace inclusion. When a model saved with a build older than 7.1 is loaded, any legacy Using «x» := «expr» declaration is automatically rewritten to Local «x» := «expr» on load, so existing models continue to evaluate exactly as before.
See also
- Namespaces
- NamespaceImports
- Namespace attribute
- Local..Do
- Var..Do
Enable comment auto-refresher