aboutsummaryrefslogtreecommitdiff
path: root/runtime/doc
diff options
context:
space:
mode:
authorMichael Ennen <mike.ennen@gmail.com>2016-12-17 13:07:37 -0700
committerMichael Ennen <mike.ennen@gmail.com>2017-02-14 17:38:17 -0700
commit9f6f7fe26d7caa89083f5d5b00c55bf2046591ca (patch)
treee5a2b9c4cd845a4d502f287fe31a25d117889af0 /runtime/doc
parent6563d859904837790515d790ecadaa4f06064471 (diff)
downloadrneovim-9f6f7fe26d7caa89083f5d5b00c55bf2046591ca.tar.gz
rneovim-9f6f7fe26d7caa89083f5d5b00c55bf2046591ca.tar.bz2
rneovim-9f6f7fe26d7caa89083f5d5b00c55bf2046591ca.zip
vim-patch:7.4.2119
Problem: Closures are not supported. Solution: Capture variables in lambdas from the outer scope. (Yasuhiro Matsumoto, Ken Takata) https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Diffstat (limited to 'runtime/doc')
-rw-r--r--runtime/doc/eval.txt20
1 files changed, 19 insertions, 1 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 62ee26cf54..fb4ca824a3 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1186,7 +1186,7 @@ the following ways:
1. The body of the lambda expression is an |expr1| and not a sequence of |Ex|
commands.
-2. The prefix "a:" is optional for arguments. E.g.: >
+2. The prefix "a:" should not be used for arguments. E.g.: >
:let F = {arg1, arg2 -> arg1 - arg2}
:echo F(5, 2)
< 3
@@ -1195,6 +1195,18 @@ The arguments are optional. Example: >
:let F = {-> 'error function'}
:echo F()
< error function
+ *closure*
+Lambda expressions can access outer scope variables and arguments. This is
+often called a closure. Example where "i" a and "a:arg" are used in a lambda
+while they exists in the function scope. They remain valid even after the
+function returns: >
+ :function Foo(arg)
+ : let i = 3
+ : return {x -> x + i - a:arg}
+ :endfunction
+ :let Bar = Foo(4)
+ :echo Bar(6)
+< 5
Examples for using a lambda expression with |sort()|, |map()| and |filter()|: >
:echo map([1, 2, 3], {idx, val -> val + 1})
@@ -1212,6 +1224,12 @@ The lambda expression is also useful for Channel, Job and timer: >
Note how execute() is used to execute an Ex command. That's ugly though.
+
+Lambda expressions have internal names like '<lambda>42'. If you get an error
+for a lambda expression, you can find what it is with the following command: >
+ :function {'<lambda>42'}
+See also: |numbered-function|
+
==============================================================================
3. Internal variable *internal-variables* *E461*