Add docs for constraining and qualifying imports.
This commit is contained in:
parent
1280c56f38
commit
74af6351b2
1 changed files with 35 additions and 0 deletions
35
doc/tut1.txt
35
doc/tut1.txt
|
|
@ -1582,6 +1582,17 @@ rules apply:
|
||||||
write(stdout, x(3)) # ambiguous: which `x` is to call?
|
write(stdout, x(3)) # ambiguous: which `x` is to call?
|
||||||
|
|
||||||
|
|
||||||
|
Excluding symbols
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
The normal ``import`` statement will bring in all exported symbols.
|
||||||
|
These can be limited by naming symbols which should be excluded with
|
||||||
|
the ``except`` qualifier.
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
import mymodule except y
|
||||||
|
|
||||||
|
|
||||||
From statement
|
From statement
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
|
@ -1592,6 +1603,30 @@ exported symbols. An alternative that only imports listed symbols is the
|
||||||
.. code-block:: nimrod
|
.. code-block:: nimrod
|
||||||
from mymodule import x, y, z
|
from mymodule import x, y, z
|
||||||
|
|
||||||
|
The ``from`` statement can also force namespace qualification on
|
||||||
|
symbols, thereby making symbols available, but needing to be qualified
|
||||||
|
to be used.
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
from mymodule import x, y, z
|
||||||
|
|
||||||
|
x() # use x without any qualification
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
from mymodule import nil
|
||||||
|
|
||||||
|
mymodule.x() # must qualify x with the module name as prefix
|
||||||
|
|
||||||
|
x() # using x here without qualification is a compile error
|
||||||
|
|
||||||
|
Since module names are generally long to be descriptive, you can also
|
||||||
|
define a shorter alias to use when qualifying symbols.
|
||||||
|
|
||||||
|
.. code-block:: nimrod
|
||||||
|
from mymodule as m import nil
|
||||||
|
|
||||||
|
m.x() # m is aliasing mymodule
|
||||||
|
|
||||||
|
|
||||||
Include statement
|
Include statement
|
||||||
-----------------
|
-----------------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue