summaryrefslogtreecommitdiff
path: root/runtime/doc/eval.txt
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-07-29 22:15:09 +0200
committerBram Moolenaar <Bram@vim.org>2016-07-29 22:15:09 +0200
commit1e96d9bf98f9ab84d5af7f98d6a961d91b17364f (patch)
treedd81c13eb8896eb9b5c3a5f311eefdd39829c907 /runtime/doc/eval.txt
parent83a2a80d6f699ad9a236431170038698e355c025 (diff)
downloadvim-git-1e96d9bf98f9ab84d5af7f98d6a961d91b17364f.tar.gz
patch 7.4.2119v7.4.2119
Problem: Closures are not supported. Solution: Capture variables in lambdas from the outer scope. (Yasuhiro Matsumoto, Ken Takata)
Diffstat (limited to 'runtime/doc/eval.txt')
-rw-r--r--runtime/doc/eval.txt27
1 files changed, 23 insertions, 4 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 7b421aa11..196e71cf0 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1,4 +1,4 @@
-*eval.txt* For Vim version 7.4. Last change: 2016 Jul 24
+*eval.txt* For Vim version 7.4. Last change: 2016 Jul 29
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -40,7 +40,7 @@ done, the features in this document are not available. See |+eval| and
There are nine types of variables:
Number A 32 or 64 bit signed number. |expr-number| *Number*
- 64-bit Number is available only when compiled with the
+ 64-bit Numbers are available only when compiled with the
|+num64| feature.
Examples: -123 0x10 0177
@@ -1219,7 +1219,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
@@ -1228,6 +1228,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})
@@ -1245,6 +1257,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*
@@ -7494,7 +7512,8 @@ test_null_string() *test_null_string()*
test_settime({expr}) *test_settime()*
Set the time Vim uses internally. Currently only used for
- timestamps in the history, as they are used in viminfo.
+ timestamps in the history, as they are used in viminfo, and
+ for undo.
{expr} must evaluate to a number. When the value is zero the
normal behavior is restored.