summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorGrzegorz Adam Hankiewicz <gradha@imap.cc>2013-12-22 00:02:01 +0100
committerGrzegorz Adam Hankiewicz <gradha@imap.cc>2013-12-23 19:25:53 +0100
commit1fe8b013effba1df6166d9596ae246bca2e05105 (patch)
treeb3e15c490901133dd3163da5a246b7f5f7835fa3
parentc3b3339e779dfe19ed1891295a763aea47981131 (diff)
downloadNim-1fe8b013effba1df6166d9596ae246bca2e05105.tar.gz
Adds example to locals() docstring.
-rw-r--r--lib/system.nim18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/system.nim b/lib/system.nim
index 106eb04a3..26109bb97 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -2675,5 +2675,21 @@ proc locals*(): TObject {.magic: "Locals", noSideEffect.} =
   ## in the current scope. This is quite fast as it does not rely
   ## on any debug or runtime information. Note that in constrast to what
   ## the official signature says, the return type is not ``TObject`` but a
-  ## tuple of a structure that depends on the current scope.
+  ## tuple of a structure that depends on the current scope. Example:
+  ##
+  ## .. code-block:: nimrod
+  ##   proc testLocals() =
+  ##     var
+  ##       a = "something"
+  ##       b = 4
+  ##       c = locals()
+  ##       d = "super!"
+  ##
+  ##     b = 1
+  ##     for name, value in fieldPairs(c):
+  ##       echo "name ", name, " with value ", value
+  ##     echo "B is ", b
+  ##   # -> name a with value something
+  ##   # -> name b with value 4
+  ##   # -> B is 1
   nil