fixes #171
This commit is contained in:
parent
489dac75c8
commit
c1c059356c
1 changed files with 41 additions and 0 deletions
|
|
@ -2958,6 +2958,47 @@ In templates identifiers can be constructed with the backticks notation:
|
|||
In the example ``name`` is instantiated with ``myint``, so \`T name\` becomes
|
||||
``Tmyint``.
|
||||
|
||||
|
||||
Lookup rules for template parameters
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
A parameter ``p`` in a template is even substituted in the expression ``x.p``.
|
||||
Thus template arguments can be used as field names and a global symbol can be
|
||||
covered by the same argument name even when fully qualified:
|
||||
|
||||
.. code-block:: nimrod
|
||||
# module 'm'
|
||||
|
||||
type
|
||||
TLev = enum
|
||||
levA, levB
|
||||
|
||||
var abclev = levB
|
||||
|
||||
template tstLev(abclev: TLev) =
|
||||
echo abclev, " ", m.abclev
|
||||
|
||||
tstLev(levA)
|
||||
# produces: 'levA levA'
|
||||
|
||||
But the global symbol can properly be captured by a ``bind`` statement:
|
||||
|
||||
.. code-block:: nimrod
|
||||
# module 'm'
|
||||
|
||||
type
|
||||
TLev = enum
|
||||
levA, levB
|
||||
|
||||
var abclev = levB
|
||||
|
||||
template tstLev(abclev: TLev) =
|
||||
bind m.abclev
|
||||
echo abclev, " ", m.abclev
|
||||
|
||||
tstLev(levA)
|
||||
# produces: 'levA levB'
|
||||
|
||||
|
||||
Macros
|
||||
------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue