diff options
author | Araq <rumpf_a@web.de> | 2012-07-25 23:34:16 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-07-25 23:34:16 +0200 |
commit | c1c059356cd6f1a6320226050f10761c1b987606 (patch) | |
tree | 617b90841d5ff5041f727002efd4c90cec9510f1 /doc | |
parent | 489dac75c81395379b2a2addfb9cc661c7c06ffd (diff) | |
download | Nim-c1c059356cd6f1a6320226050f10761c1b987606.tar.gz |
fixes #171
Diffstat (limited to 'doc')
-rwxr-xr-x | doc/manual.txt | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/doc/manual.txt b/doc/manual.txt index ddfe594a8..665ca265c 100755 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -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 ------ |