comparison runtime/doc/eval.txt @ 17612:e259d11e2900 v8.1.1803

patch 8.1.1803: all builtin functions are global commit https://github.com/vim/vim/commit/ac92e25a33c37ec5becbfffeccda136c73b761ac Author: Bram Moolenaar <Bram@vim.org> Date: Sat Aug 3 21:58:38 2019 +0200 patch 8.1.1803: all builtin functions are global Problem: All builtin functions are global. Solution: Add the method call operator ->. Implemented for a limited number of functions.
author Bram Moolenaar <Bram@vim.org>
date Sat, 03 Aug 2019 22:00:07 +0200
parents 2704c4e3e20a
children 072efa9ca875
comparison
equal deleted inserted replaced
17611:b9a3d542a042 17612:e259d11e2900
1112 This expression is either |expr9| or a sequence of the alternatives below, 1112 This expression is either |expr9| or a sequence of the alternatives below,
1113 in any order. E.g., these are all possible: 1113 in any order. E.g., these are all possible:
1114 expr9[expr1].name 1114 expr9[expr1].name
1115 expr9.name[expr1] 1115 expr9.name[expr1]
1116 expr9(expr1, ...)[expr1].name 1116 expr9(expr1, ...)[expr1].name
1117 expr9->(expr1, ...)[expr1]
1118 Evaluation is always from left to right.
1117 1119
1118 1120
1119 expr8[expr1] item of String or |List| *expr-[]* *E111* 1121 expr8[expr1] item of String or |List| *expr-[]* *E111*
1120 *E909* *subscript* 1122 *E909* *subscript*
1121 If expr8 is a Number or String this results in a String that contains the 1123 If expr8 is a Number or String this results in a String that contains the
1211 expr8(expr1, ...) |Funcref| function call 1213 expr8(expr1, ...) |Funcref| function call
1212 1214
1213 When expr8 is a |Funcref| type variable, invoke the function it refers to. 1215 When expr8 is a |Funcref| type variable, invoke the function it refers to.
1214 1216
1215 1217
1218 expr8->name([args]) method call *method*
1219
1220 For global methods this is the same as: >
1221 name(expr8 [, args])
1222 There can also be methods specifically for the type of "expr8".
1216 1223
1217 *expr9* 1224 *expr9*
1218 number 1225 number
1219 ------ 1226 ------
1220 number number constant *expr-number* 1227 number number constant *expr-number*
2875 :call add(mylist, "woodstock") 2882 :call add(mylist, "woodstock")
2876 < Note that when {expr} is a |List| it is appended as a single 2883 < Note that when {expr} is a |List| it is appended as a single
2877 item. Use |extend()| to concatenate |Lists|. 2884 item. Use |extend()| to concatenate |Lists|.
2878 When {object} is a |Blob| then {expr} must be a number. 2885 When {object} is a |Blob| then {expr} must be a number.
2879 Use |insert()| to add an item at another position. 2886 Use |insert()| to add an item at another position.
2887 Can also be used as a |method|: >
2888 mylist->add(val1)->add(val2)
2880 2889
2881 2890
2882 and({expr}, {expr}) *and()* 2891 and({expr}, {expr}) *and()*
2883 Bitwise AND on the two arguments. The arguments are converted 2892 Bitwise AND on the two arguments. The arguments are converted
2884 to a number. A List, Dict or Float argument causes an error. 2893 to a number. A List, Dict or Float argument causes an error.
3510 that the original |List| can be changed without changing the 3519 that the original |List| can be changed without changing the
3511 copy, and vice versa. But the items are identical, thus 3520 copy, and vice versa. But the items are identical, thus
3512 changing an item changes the contents of both |Lists|. 3521 changing an item changes the contents of both |Lists|.
3513 A |Dictionary| is copied in a similar way as a |List|. 3522 A |Dictionary| is copied in a similar way as a |List|.
3514 Also see |deepcopy()|. 3523 Also see |deepcopy()|.
3524 Can also be used as a |method|: >
3525 mylist->copy()
3515 3526
3516 cos({expr}) *cos()* 3527 cos({expr}) *cos()*
3517 Return the cosine of {expr}, measured in radians, as a |Float|. 3528 Return the cosine of {expr}, measured in radians, as a |Float|.
3518 {expr} must evaluate to a |Float| or a |Number|. 3529 {expr} must evaluate to a |Float| or a |Number|.
3519 Examples: > 3530 Examples: >
3546 When {ic} is given and it's |TRUE| then case is ignored. 3557 When {ic} is given and it's |TRUE| then case is ignored.
3547 3558
3548 When {comp} is a string then the number of not overlapping 3559 When {comp} is a string then the number of not overlapping
3549 occurrences of {expr} is returned. Zero is returned when 3560 occurrences of {expr} is returned. Zero is returned when
3550 {expr} is an empty string. 3561 {expr} is an empty string.
3562 Can also be used as a |method|: >
3563 mylist->count(val)
3551 3564
3552 *cscope_connection()* 3565 *cscope_connection()*
3553 cscope_connection([{num} , {dbpath} [, {prepend}]]) 3566 cscope_connection([{num} , {dbpath} [, {prepend}]])
3554 Checks for the existence of a |cscope| connection. If no 3567 Checks for the existence of a |cscope| connection. If no
3555 parameters are specified, then the function returns: 3568 parameters are specified, then the function returns:
3729 - A |Channel| is empty when it is closed. 3742 - A |Channel| is empty when it is closed.
3730 - A |Blob| is empty when its length is zero. 3743 - A |Blob| is empty when its length is zero.
3731 3744
3732 For a long |List| this is much faster than comparing the 3745 For a long |List| this is much faster than comparing the
3733 length with zero. 3746 length with zero.
3747 Can also be used as a |method|: >
3748 mylist->empty()
3734 3749
3735 escape({string}, {chars}) *escape()* 3750 escape({string}, {chars}) *escape()*
3736 Escape the characters in {chars} that occur in {string} with a 3751 Escape the characters in {chars} that occur in {string} with a
3737 backslash. Example: > 3752 backslash. Example: >
3738 :echo escape('c:\program files\vim', ' \') 3753 :echo escape('c:\program files\vim', ' \')
4039 {expr2} remains unchanged. 4054 {expr2} remains unchanged.
4040 When {expr1} is locked and {expr2} is not empty the operation 4055 When {expr1} is locked and {expr2} is not empty the operation
4041 fails. 4056 fails.
4042 Returns {expr1}. 4057 Returns {expr1}.
4043 4058
4059 Can also be used as a |method|: >
4060 mylist->extend(otherlist)
4061
4044 4062
4045 feedkeys({string} [, {mode}]) *feedkeys()* 4063 feedkeys({string} [, {mode}]) *feedkeys()*
4046 Characters in {string} are queued for processing as if they 4064 Characters in {string} are queued for processing as if they
4047 come from a mapping or were typed by the user. 4065 come from a mapping or were typed by the user.
4048 4066
4152 When an error is encountered while evaluating {expr2} no 4170 When an error is encountered while evaluating {expr2} no
4153 further items in {expr1} are processed. When {expr2} is a 4171 further items in {expr1} are processed. When {expr2} is a
4154 Funcref errors inside a function are ignored, unless it was 4172 Funcref errors inside a function are ignored, unless it was
4155 defined with the "abort" flag. 4173 defined with the "abort" flag.
4156 4174
4175 Can also be used as a |method|: >
4176 mylist->filter(expr2)
4157 4177
4158 finddir({name} [, {path} [, {count}]]) *finddir()* 4178 finddir({name} [, {path} [, {count}]]) *finddir()*
4159 Find directory {name} in {path}. Supports both downwards and 4179 Find directory {name} in {path}. Supports both downwards and
4160 upwards recursive directory searches. See |file-searching| 4180 upwards recursive directory searches. See |file-searching|
4161 for the syntax of {path}. 4181 for the syntax of {path}.
4414 4434
4415 get({list}, {idx} [, {default}]) *get()* 4435 get({list}, {idx} [, {default}]) *get()*
4416 Get item {idx} from |List| {list}. When this item is not 4436 Get item {idx} from |List| {list}. When this item is not
4417 available return {default}. Return zero when {default} is 4437 available return {default}. Return zero when {default} is
4418 omitted. 4438 omitted.
4439 Can also be used as a |method|: >
4440 mylist->get(idx)
4419 get({blob}, {idx} [, {default}]) 4441 get({blob}, {idx} [, {default}])
4420 Get byte {idx} from |Blob| {blob}. When this byte is not 4442 Get byte {idx} from |Blob| {blob}. When this byte is not
4421 available return {default}. Return -1 when {default} is 4443 available return {default}. Return -1 when {default} is
4422 omitted. 4444 omitted.
4423 get({dict}, {key} [, {default}]) 4445 get({dict}, {key} [, {default}])
5687 :call insert(mylist, 6, len(mylist)) 5709 :call insert(mylist, 6, len(mylist))
5688 < The last example can be done simpler with |add()|. 5710 < The last example can be done simpler with |add()|.
5689 Note that when {item} is a |List| it is inserted as a single 5711 Note that when {item} is a |List| it is inserted as a single
5690 item. Use |extend()| to concatenate |Lists|. 5712 item. Use |extend()| to concatenate |Lists|.
5691 5713
5714 Can also be used as a |method|: >
5715 mylist->insert(item)
5716
5692 invert({expr}) *invert()* 5717 invert({expr}) *invert()*
5693 Bitwise invert. The argument is converted to a number. A 5718 Bitwise invert. The argument is converted to a number. A
5694 List, Dict or Float argument causes an error. Example: > 5719 List, Dict or Float argument causes an error. Example: >
5695 :let bits = invert(bits) 5720 :let bits = invert(bits)
5696 5721
5738 Example: > 5763 Example: >
5739 for [key, value] in items(mydict) 5764 for [key, value] in items(mydict)
5740 echo key . ': ' . value 5765 echo key . ': ' . value
5741 endfor 5766 endfor
5742 5767
5768 < Can also be used as a |method|: >
5769 mydict->items()
5743 5770
5744 job_ functions are documented here: |job-functions-details| 5771 job_ functions are documented here: |job-functions-details|
5745 5772
5746 5773
5747 join({list} [, {sep}]) *join()* 5774 join({list} [, {sep}]) *join()*
5752 add it there too: > 5779 add it there too: >
5753 let lines = join(mylist, "\n") . "\n" 5780 let lines = join(mylist, "\n") . "\n"
5754 < String items are used as-is. |Lists| and |Dictionaries| are 5781 < String items are used as-is. |Lists| and |Dictionaries| are
5755 converted into a string like with |string()|. 5782 converted into a string like with |string()|.
5756 The opposite function is |split()|. 5783 The opposite function is |split()|.
5784
5785 Can also be used as a |method|: >
5786 mylist->join()
5757 5787
5758 js_decode({string}) *js_decode()* 5788 js_decode({string}) *js_decode()*
5759 This is similar to |json_decode()| with these differences: 5789 This is similar to |json_decode()| with these differences:
5760 - Object key names do not have to be in quotes. 5790 - Object key names do not have to be in quotes.
5761 - Strings can be in single quotes. 5791 - Strings can be in single quotes.
5838 5868
5839 keys({dict}) *keys()* 5869 keys({dict}) *keys()*
5840 Return a |List| with all the keys of {dict}. The |List| is in 5870 Return a |List| with all the keys of {dict}. The |List| is in
5841 arbitrary order. Also see |items()| and |values()|. 5871 arbitrary order. Also see |items()| and |values()|.
5842 5872
5843 *len()* *E701* 5873 Can also be used as a |method|: >
5874 mydict->keys()
5875
5876 < *len()* *E701*
5844 len({expr}) The result is a Number, which is the length of the argument. 5877 len({expr}) The result is a Number, which is the length of the argument.
5845 When {expr} is a String or a Number the length in bytes is 5878 When {expr} is a String or a Number the length in bytes is
5846 used, as with |strlen()|. 5879 used, as with |strlen()|.
5847 When {expr} is a |List| the number of items in the |List| is 5880 When {expr} is a |List| the number of items in the |List| is
5848 returned. 5881 returned.
5849 When {expr} is a |Blob| the number of bytes is returned. 5882 When {expr} is a |Blob| the number of bytes is returned.
5850 When {expr} is a |Dictionary| the number of entries in the 5883 When {expr} is a |Dictionary| the number of entries in the
5851 |Dictionary| is returned. 5884 |Dictionary| is returned.
5852 Otherwise an error is given. 5885 Otherwise an error is given.
5853 5886
5854 *libcall()* *E364* *E368* 5887 Can also be used as a |method|: >
5888 mylist->len()
5889
5890 < *libcall()* *E364* *E368*
5855 libcall({libname}, {funcname}, {argument}) 5891 libcall({libname}, {funcname}, {argument})
5856 Call function {funcname} in the run-time library {libname} 5892 Call function {funcname} in the run-time library {libname}
5857 with single argument {argument}. 5893 with single argument {argument}.
5858 This is useful to call functions in a library that you 5894 This is useful to call functions in a library that you
5859 especially made to be used with Vim. Since only one argument 5895 especially made to be used with Vim. Since only one argument
6134 When an error is encountered while evaluating {expr2} no 6170 When an error is encountered while evaluating {expr2} no
6135 further items in {expr1} are processed. When {expr2} is a 6171 further items in {expr1} are processed. When {expr2} is a
6136 Funcref errors inside a function are ignored, unless it was 6172 Funcref errors inside a function are ignored, unless it was
6137 defined with the "abort" flag. 6173 defined with the "abort" flag.
6138 6174
6175 Can also be used as a |method|: >
6176 mylist->map(expr2)
6139 6177
6140 maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()* 6178 maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
6141 When {dict} is omitted or zero: Return the rhs of mapping 6179 When {dict} is omitted or zero: Return the rhs of mapping
6142 {name} in mode {mode}. The returned String has special 6180 {name} in mode {mode}. The returned String has special
6143 characters translated like in the output of the ":map" command 6181 characters translated like in the output of the ":map" command
6460 it returns the maximum of all values in the dictionary. 6498 it returns the maximum of all values in the dictionary.
6461 If {expr} is neither a list nor a dictionary, or one of the 6499 If {expr} is neither a list nor a dictionary, or one of the
6462 items in {expr} cannot be used as a Number this results in 6500 items in {expr} cannot be used as a Number this results in
6463 an error. An empty |List| or |Dictionary| results in zero. 6501 an error. An empty |List| or |Dictionary| results in zero.
6464 6502
6465 *min()* 6503 Can also be used as a |method|: >
6504 mylist->max()
6505
6506 < *min()*
6466 min({expr}) Return the minimum value of all items in {expr}. 6507 min({expr}) Return the minimum value of all items in {expr}.
6467 {expr} can be a list or a dictionary. For a dictionary, 6508 {expr} can be a list or a dictionary. For a dictionary,
6468 it returns the minimum of all values in the dictionary. 6509 it returns the minimum of all values in the dictionary.
6469 If {expr} is neither a list nor a dictionary, or one of the 6510 If {expr} is neither a list nor a dictionary, or one of the
6470 items in {expr} cannot be used as a Number this results in 6511 items in {expr} cannot be used as a Number this results in
6471 an error. An empty |List| or |Dictionary| results in zero. 6512 an error. An empty |List| or |Dictionary| results in zero.
6472 6513
6473 *mkdir()* *E739* 6514 Can also be used as a |method|: >
6515 mylist->min()
6516
6517 < *mkdir()* *E739*
6474 mkdir({name} [, {path} [, {prot}]]) 6518 mkdir({name} [, {path} [, {prot}]])
6475 Create directory {name}. 6519 Create directory {name}.
6476 6520
6477 If {path} is "p" then intermediate directories are created as 6521 If {path} is "p" then intermediate directories are created as
6478 necessary. Otherwise it must be "". 6522 necessary. Otherwise it must be "".
7152 :echo "last item: " . remove(mylist, -1) 7196 :echo "last item: " . remove(mylist, -1)
7153 :call remove(mylist, 0, 9) 7197 :call remove(mylist, 0, 9)
7154 < 7198 <
7155 Use |delete()| to remove a file. 7199 Use |delete()| to remove a file.
7156 7200
7201 Can also be used as a |method|: >
7202 mylist->remove(idx)
7203
7157 remove({blob}, {idx} [, {end}]) 7204 remove({blob}, {idx} [, {end}])
7158 Without {end}: Remove the byte at {idx} from |Blob| {blob} and 7205 Without {end}: Remove the byte at {idx} from |Blob| {blob} and
7159 return the byte. 7206 return the byte.
7160 With {end}: Remove bytes from {idx} to {end} (inclusive) and 7207 With {end}: Remove bytes from {idx} to {end} (inclusive) and
7161 return a |Blob| with these bytes. When {idx} points to the same 7208 return a |Blob| with these bytes. When {idx} points to the same
7187 When {expr} is a |List| the result is {expr} concatenated 7234 When {expr} is a |List| the result is {expr} concatenated
7188 {count} times. Example: > 7235 {count} times. Example: >
7189 :let longlist = repeat(['a', 'b'], 3) 7236 :let longlist = repeat(['a', 'b'], 3)
7190 < Results in ['a', 'b', 'a', 'b', 'a', 'b']. 7237 < Results in ['a', 'b', 'a', 'b', 'a', 'b'].
7191 7238
7239 Can also be used as a |method|: >
7240 mylist->repeat(count)
7192 7241
7193 resolve({filename}) *resolve()* *E655* 7242 resolve({filename}) *resolve()* *E655*
7194 On MS-Windows, when {filename} is a shortcut (a .lnk file), 7243 On MS-Windows, when {filename} is a shortcut (a .lnk file),
7195 returns the path the shortcut points to in a simplified form. 7244 returns the path the shortcut points to in a simplified form.
7196 When {filename} is a symbolic link or junction point, return 7245 When {filename} is a symbolic link or junction point, return
7204 The simplification step is done as by |simplify()|. 7253 The simplification step is done as by |simplify()|.
7205 resolve() keeps a leading path component specifying the 7254 resolve() keeps a leading path component specifying the
7206 current directory (provided the result is still a relative 7255 current directory (provided the result is still a relative
7207 path name) and also keeps a trailing path separator. 7256 path name) and also keeps a trailing path separator.
7208 7257
7209 *reverse()* 7258
7210 reverse({object}) 7259 reverse({object}) *reverse()*
7211 Reverse the order of items in {object} in-place. 7260 Reverse the order of items in {object} in-place.
7212 {object} can be a |List| or a |Blob|. 7261 {object} can be a |List| or a |Blob|.
7213 Returns {object}. 7262 Returns {object}.
7214 If you want an object to remain unmodified make a copy first: > 7263 If you want an object to remain unmodified make a copy first: >
7215 :let revlist = reverse(copy(mylist)) 7264 :let revlist = reverse(copy(mylist))
7265 < Can also be used as a |method|: >
7266 mylist->reverse()
7216 7267
7217 round({expr}) *round()* 7268 round({expr}) *round()*
7218 Round off {expr} to the nearest integral value and return it 7269 Round off {expr} to the nearest integral value and return it
7219 as a |Float|. If {expr} lies halfway between two integral 7270 as a |Float|. If {expr} lies halfway between two integral
7220 values, then use the larger one (away from zero). 7271 values, then use the larger one (away from zero).
8068 The sort is stable, items which compare equal (as number or as 8119 The sort is stable, items which compare equal (as number or as
8069 string) will keep their relative position. E.g., when sorting 8120 string) will keep their relative position. E.g., when sorting
8070 on numbers, text strings will sort next to each other, in the 8121 on numbers, text strings will sort next to each other, in the
8071 same order as they were originally. 8122 same order as they were originally.
8072 8123
8073 Also see |uniq()|. 8124 Can also be used as a |method|: >
8125 mylist->sort()
8126
8127 < Also see |uniq()|.
8074 8128
8075 Example: > 8129 Example: >
8076 func MyCompare(i1, i2) 8130 func MyCompare(i1, i2)
8077 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1 8131 return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
8078 endfunc 8132 endfunc
8376 8430
8377 When a List or Dictionary has a recursive reference it is 8431 When a List or Dictionary has a recursive reference it is
8378 replaced by "[...]" or "{...}". Using eval() on the result 8432 replaced by "[...]" or "{...}". Using eval() on the result
8379 will then fail. 8433 will then fail.
8380 8434
8381 Also see |strtrans()|. 8435 Can also be used as a |method|: >
8436 mylist->string()
8437
8438 < Also see |strtrans()|.
8382 8439
8383 *strlen()* 8440 *strlen()*
8384 strlen({expr}) The result is a Number, which is the length of the String 8441 strlen({expr}) The result is a Number, which is the length of the String
8385 {expr} in bytes. 8442 {expr} in bytes.
8386 If the argument is a Number it is first converted to a String. 8443 If the argument is a Number it is first converted to a String.
8998 :if type(myvar) == type(v:false) 9055 :if type(myvar) == type(v:false)
8999 :if type(myvar) == type(v:none) 9056 :if type(myvar) == type(v:none)
9000 < To check if the v:t_ variables exist use this: > 9057 < To check if the v:t_ variables exist use this: >
9001 :if exists('v:t_number') 9058 :if exists('v:t_number')
9002 9059
9060 < Can also be used as a |method|: >
9061 mylist->type()
9062
9003 undofile({name}) *undofile()* 9063 undofile({name}) *undofile()*
9004 Return the name of the undo file that would be used for a file 9064 Return the name of the undo file that would be used for a file
9005 with name {name} when writing. This uses the 'undodir' 9065 with name {name} when writing. This uses the 'undodir'
9006 option, finding directories that exist. It does not check if 9066 option, finding directories that exist. It does not check if
9007 the undo file exists. 9067 the undo file exists.
9062 to remain unmodified make a copy first: > 9122 to remain unmodified make a copy first: >
9063 :let newlist = uniq(copy(mylist)) 9123 :let newlist = uniq(copy(mylist))
9064 < The default compare function uses the string representation of 9124 < The default compare function uses the string representation of
9065 each item. For the use of {func} and {dict} see |sort()|. 9125 each item. For the use of {func} and {dict} see |sort()|.
9066 9126
9127 Can also be used as a |method|: >
9128 mylist->uniq()
9129
9067 values({dict}) *values()* 9130 values({dict}) *values()*
9068 Return a |List| with all the values of {dict}. The |List| is 9131 Return a |List| with all the values of {dict}. The |List| is
9069 in arbitrary order. Also see |items()| and |keys()|. 9132 in arbitrary order. Also see |items()| and |keys()|.
9070 9133
9134 Can also be used as a |method|: >
9135 mydict->values()
9071 9136
9072 virtcol({expr}) *virtcol()* 9137 virtcol({expr}) *virtcol()*
9073 The result is a Number, which is the screen column of the file 9138 The result is a Number, which is the screen column of the file
9074 position given with {expr}. That is, the last screen position 9139 position given with {expr}. That is, the last screen position
9075 occupied by the character at that position, when the screen 9140 occupied by the character at that position, when the screen