clarify scoped names a bit more

This commit is contained in:
Irmen de Jong 2023-12-28 16:36:29 +01:00
parent 9c1b11d605
commit 078bfefe41
3 changed files with 15 additions and 2 deletions

View File

@ -111,11 +111,14 @@ Be careful when importing other modules; blocks in your own code cannot have
the same name as a block defined in an imported module or library.
.. sidebar::
Use qualified names ("dotted names") to reference symbols defined elsewhere
Using qualified names ("dotted names") to reference symbols defined elsewhere
In prog8 every symbol is 'public' and can be accessed from anywhere else, given its *full* "dotted name".
Every symbol is 'public' and can be accessed from anywhere else, when given its *full* "dotted name".
So, accessing a variable ``counter`` defined in subroutine ``worker`` in block ``main``,
can be done from anywhere by using ``main.worker.counter``.
Unlike most other programming langues, as soon as a name is scoped,
Prog8 treats it as a name starting in the *global* namespace.
Relative name lookup is only performed for *non-scoped* names.
The address can be used to place a block at a specific location in memory.
Usually it is omitted, and the compiler will automatically choose the location (usually immediately after

View File

@ -270,6 +270,15 @@ Examples of valid identifiers::
приблизительно
π
**Scoped names**
Sometimes called "qualified names" or "dotted names", a scoped name is a sequence of identifiers separated by a dot.
They are used to reference symbols in other scopes. Note that unlike many other programming languages,
scoped names always need to be fully scoped (because they always start in the global scope). Also see :ref:`blocks`::
main.start ; the entrypoint subroutine
main.start.variable ; a variable in the entrypoint subroutine
Code blocks
-----------

View File

@ -2,6 +2,7 @@
TODO
====
- add functions to const eval that we know how to evaluate (math.*, etc)
- [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....
...