Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update document for closureScope and capture #12886

Merged
merged 2 commits into from
Dec 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/manual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------
Expand Down
7 changes: 6 additions & 1 deletion lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down