Skip to content

Commit 1860cb7

Browse files
committed
docs: clarify imports and scoping
1 parent 6598761 commit 1860cb7

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

docs/source/imports-and-scoping.rst

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ All ordinary commands are valid inside a section, including other section comman
3737

3838
Like a file, a section has both a visible namespace and an export namespace, and ``import`` statements in a section only affect the visible namespace. Thus, imported names are no longer visible after the section is closed. But as with importing files, if you use ``export`` instead inside a section, then the imported names are placed in export namespace; thus when the section is closed they are treated like constants defined in the section and are merged into the outer namespace with the section name prefix.
3939

40+
Since a namespace simply consists of all constants whose name begins with a certain prefix, you can add to it (or "patch" it) at any time, simply by defining more such constants. To define many more such constants at once, you can open another section with the same name. Note, however, that "re-opening" a namespace like this does not automatically import the previously contents of that namespace. That is:
41+
42+
.. code-block:: none
43+
44+
section nat ≔
45+
def plus ≔ BODY
46+
` Here the above definition is called "plus"
47+
end
48+
49+
` Here the above definition is called "nat.plus"
50+
51+
section nat ≔
52+
` Here the above definition is still called "nat.plus"
53+
end
54+
55+
If you want to import the previous contents, you can say ``import nat`` in the second ``section``; see :ref:`Importing namespaces`.
56+
4057

4158
Import modifiers
4259
----------------
@@ -77,7 +94,13 @@ Imported names also remain available in their original locations; there is no wa
7794
Importing notations
7895
-------------------
7996

80-
Visibility of notations defined by another file, or in a section, is implemented as a special case of importing names. Specifically, when a new notation is declared, it is associated to a name in the current namespace prefixed by ``notations``. The name is obtained from its pattern by replacing variables with underscores, concatenating them with the symbols (unquoted) separated by spaces, and surrounding it in guillemets ``«»`` to make it an atomic identifier. Thus, for instance, ``notation(1) x "+" y ≔ plus x y`` associates this notation to the name ``notations.«_ + _»``.
97+
Visibility of notations defined by another file, or in a section, is implemented as a special case of importing names. Specifically, when a new notation is declared, it is associated to a name in the current namespace prefixed by ``notations``. The name is obtained from its pattern by replacing variables with underscores, concatenating them with the symbols (unquoted) separated by spaces, and surrounding it in guillemets ``«»`` to make it an atomic identifier (see :ref:`Identifiers`). Thus, for instance,
98+
99+
.. code-block:: none
100+
101+
notation(1) x "+" y ≔ plus x y
102+
103+
associates this notation to the name ``notations.«_ + _»``.
81104

82105
Then, whenever another file or section is imported, any notations that are present in the ``notations`` namespace after the modifiers are applied become available in the current file. Since by default the complete namespace of an imported file is merged with the current one, this means that by default all notations defined in that file also become available.
83106

@@ -113,7 +136,7 @@ Whenever a file ``FILE.ny`` is successfully executed, Narya writes a "compiled"
113136
1. ``-source-only`` was not specified,
114137
2. ``FILE.ny`` was not specified explicitly on the command-line (so that it must have been imported by another file),
115138
3. ``FILE.nyo`` exists in the same directory,
116-
4. the same type theory flags (``-arity``, ``-direction``, ``-internal``/``-external``, and ``-discreteness``) are in effect now as when ``FILE.nyo`` was compiled,
139+
4. the same type theory flags (``-parametric``, ``-arity``, ``-direction``, ``-internal``/``-external``, and ``-discreteness``) are in effect now as when ``FILE.nyo`` was compiled,
117140
5. ``FILE.ny`` has not been modified more recently than ``FILE.nyo``, and
118141
6. none of the files imported by ``FILE.ny`` are newer than it or their compiled versions,
119142

0 commit comments

Comments
 (0)