diff options
author | Araq <rumpf_a@web.de> | 2012-08-25 01:34:50 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-08-25 01:34:50 +0200 |
commit | 9a7f0cd8510a534a3f1e9d4275b8abd7825a94c6 (patch) | |
tree | f862293603c58003d24997781959820366284e8e /doc | |
parent | 8a92e95ccfb2653d8cea52a83c26ac8967557062 (diff) | |
download | Nim-9a7f0cd8510a534a3f1e9d4275b8abd7825a94c6.tar.gz |
bindSym suffices; no 'bind' for macros anymore
Diffstat (limited to 'doc')
-rwxr-xr-x | doc/manual.txt | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/doc/manual.txt b/doc/manual.txt index 6fccd0ca3..a78af89a6 100755 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -3154,27 +3154,22 @@ The macro call expands to: writeln(stdout, x) -Bind in macros -~~~~~~~~~~~~~~ +BindSym +~~~~~~~ The above ``debug`` macro relies on the fact that ``write``, ``writeln`` and ``stdout`` are declared in the system module and thus visible in the instantiating context. There is a way to use bound identifiers -(aka `symbols`:idx) instead of using unbound identifiers. The ``bind`` -statement plus the ``bindSym`` builtin can be used for that: +(aka `symbols`:idx) instead of using unbound identifiers. The ``bindSym`` +builtin can be used for that: .. code-block:: nimrod - # to work with Nimrod syntax trees, we need an API that is defined in the - # ``macros`` module: import macros macro debug(n: expr): stmt = - # we need to declare the used symbols here: - bind write, writeln, stdout result = newNimNode(nnkStmtList, n) - # iterate over any argument that is passed to this macro: for i in 1..n.len-1: - # we can access the bound symbol via 'bindSym': + # we can bind symbols in scope via 'bindSym': add(result, newCall(bindSym"write", bindSym"stdout", toStrLit(n[i]))) add(result, newCall(bindSym"write", bindSym"stdout", newStrLitNode(": "))) add(result, newCall(bindSym"writeln", bindSym"stdout", n[i])) @@ -3203,7 +3198,7 @@ The macro call expands to: writeln(stdout, x) However, the symbols ``write``, ``writeln`` and ``stdout`` are already bound -and are not looked up again. As the example shows, ``bind`` does work with +and are not looked up again. As the example shows, ``bindSym`` does work with overloaded symbols implicitely. |