mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
clarify scoped names a bit more
This commit is contained in:
parent
9c1b11d605
commit
078bfefe41
@ -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.
|
the same name as a block defined in an imported module or library.
|
||||||
|
|
||||||
.. sidebar::
|
.. 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``,
|
So, accessing a variable ``counter`` defined in subroutine ``worker`` in block ``main``,
|
||||||
can be done from anywhere by using ``main.worker.counter``.
|
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.
|
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
|
Usually it is omitted, and the compiler will automatically choose the location (usually immediately after
|
||||||
|
@ -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
|
Code blocks
|
||||||
-----------
|
-----------
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
TODO
|
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 ....
|
- [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....
|
||||||
|
|
||||||
...
|
...
|
||||||
|
Loading…
x
Reference in New Issue
Block a user