mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 07:43:26 +00:00
update documentation for closureScope and capture (#12886)
This commit is contained in:
@@ -3521,7 +3521,8 @@ Creating closures in loops
|
||||
|
||||
Since closures capture local variables by reference it is often not wanted
|
||||
behavior inside loop bodies. See `closureScope
|
||||
<system.html#closureScope.t,untyped>`_ for details on how to change this behavior.
|
||||
<system.html#closureScope.t,untyped>`_ and `capture
|
||||
<sugar.html#capture.m,openArray[typed],untyped>`_ for details on how to change this behavior.
|
||||
|
||||
Anonymous Procs
|
||||
---------------
|
||||
|
||||
@@ -4395,7 +4395,12 @@ when defined(nimNoNilSeqs2):
|
||||
|
||||
template closureScope*(body: untyped): untyped =
|
||||
## Useful when creating a closure in a loop to capture local loop variables by
|
||||
## their current iteration values. Example:
|
||||
## their current iteration values.
|
||||
##
|
||||
## Note: This template may not work in some cases, use
|
||||
## `capture <sugar.html#capture.m,openArray[typed],untyped>`_ instead.
|
||||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: Nim
|
||||
## var myClosure : proc()
|
||||
|
||||
Reference in New Issue
Block a user