Adds example to locals() docstring.
This commit is contained in:
parent
c3b3339e77
commit
1fe8b013ef
1 changed files with 17 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue