Skip to content

Commit ac92e25

Browse files
committed
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.
1 parent b212906 commit ac92e25

File tree

10 files changed

+336
-42
lines changed

10 files changed

+336
-42
lines changed

runtime/doc/eval.txt

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,8 @@ in any order. E.g., these are all possible:
11141114
expr9[expr1].name
11151115
expr9.name[expr1]
11161116
expr9(expr1, ...)[expr1].name
1117+
expr9->(expr1, ...)[expr1]
1118+
Evaluation is always from left to right.
11171119

11181120

11191121
expr8[expr1] item of String or |List| *expr-[]* *E111*
@@ -1213,6 +1215,11 @@ expr8(expr1, ...) |Funcref| function call
12131215
When expr8 is a |Funcref| type variable, invoke the function it refers to.
12141216

12151217

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".
12161223

12171224
*expr9*
12181225
number
@@ -2877,6 +2884,8 @@ add({object}, {expr}) *add()*
28772884
item. Use |extend()| to concatenate |Lists|.
28782885
When {object} is a |Blob| then {expr} must be a number.
28792886
Use |insert()| to add an item at another position.
2887+
Can also be used as a |method|: >
2888+
mylist->add(val1)->add(val2)
28802889
28812890
28822891
and({expr}, {expr}) *and()*
@@ -3512,6 +3521,8 @@ copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
35123521
changing an item changes the contents of both |Lists|.
35133522
A |Dictionary| is copied in a similar way as a |List|.
35143523
Also see |deepcopy()|.
3524+
Can also be used as a |method|: >
3525+
mylist->copy()
35153526
35163527
cos({expr}) *cos()*
35173528
Return the cosine of {expr}, measured in radians, as a |Float|.
@@ -3548,6 +3559,8 @@ count({comp}, {expr} [, {ic} [, {start}]]) *count()*
35483559
When {comp} is a string then the number of not overlapping
35493560
occurrences of {expr} is returned. Zero is returned when
35503561
{expr} is an empty string.
3562+
Can also be used as a |method|: >
3563+
mylist->count(val)
35513564
35523565
*cscope_connection()*
35533566
cscope_connection([{num} , {dbpath} [, {prepend}]])
@@ -3731,6 +3744,8 @@ empty({expr}) *empty()*
37313744

37323745
For a long |List| this is much faster than comparing the
37333746
length with zero.
3747+
Can also be used as a |method|: >
3748+
mylist->empty()
37343749
37353750
escape({string}, {chars}) *escape()*
37363751
Escape the characters in {chars} that occur in {string} with a
@@ -4041,6 +4056,9 @@ extend({expr1}, {expr2} [, {expr3}]) *extend()*
40414056
fails.
40424057
Returns {expr1}.
40434058

4059+
Can also be used as a |method|: >
4060+
mylist->extend(otherlist)
4061+
40444062
40454063
feedkeys({string} [, {mode}]) *feedkeys()*
40464064
Characters in {string} are queued for processing as if they
@@ -4154,6 +4172,8 @@ filter({expr1}, {expr2}) *filter()*
41544172
Funcref errors inside a function are ignored, unless it was
41554173
defined with the "abort" flag.
41564174

4175+
Can also be used as a |method|: >
4176+
mylist->filter(expr2)
41574177
41584178
finddir({name} [, {path} [, {count}]]) *finddir()*
41594179
Find directory {name} in {path}. Supports both downwards and
@@ -4416,6 +4436,8 @@ get({list}, {idx} [, {default}]) *get()*
44164436
Get item {idx} from |List| {list}. When this item is not
44174437
available return {default}. Return zero when {default} is
44184438
omitted.
4439+
Can also be used as a |method|: >
4440+
mylist->get(idx)
44194441
get({blob}, {idx} [, {default}])
44204442
Get byte {idx} from |Blob| {blob}. When this byte is not
44214443
available return {default}. Return -1 when {default} is
@@ -5689,6 +5711,9 @@ insert({object}, {item} [, {idx}]) *insert()*
56895711
Note that when {item} is a |List| it is inserted as a single
56905712
item. Use |extend()| to concatenate |Lists|.
56915713

5714+
Can also be used as a |method|: >
5715+
mylist->insert(item)
5716+
56925717
invert({expr}) *invert()*
56935718
Bitwise invert. The argument is converted to a number. A
56945719
List, Dict or Float argument causes an error. Example: >
@@ -5740,6 +5765,8 @@ items({dict}) *items()*
57405765
echo key . ': ' . value
57415766
endfor
57425767
5768+
< Can also be used as a |method|: >
5769+
mydict->items()
57435770
57445771
job_ functions are documented here: |job-functions-details|
57455772

@@ -5755,6 +5782,9 @@ join({list} [, {sep}]) *join()*
57555782
converted into a string like with |string()|.
57565783
The opposite function is |split()|.
57575784

5785+
Can also be used as a |method|: >
5786+
mylist->join()
5787+
57585788
js_decode({string}) *js_decode()*
57595789
This is similar to |json_decode()| with these differences:
57605790
- Object key names do not have to be in quotes.
@@ -5840,7 +5870,10 @@ keys({dict}) *keys()*
58405870
Return a |List| with all the keys of {dict}. The |List| is in
58415871
arbitrary order. Also see |items()| and |values()|.
58425872

5843-
*len()* *E701*
5873+
Can also be used as a |method|: >
5874+
mydict->keys()
5875+
5876+
< *len()* *E701*
58445877
len({expr}) The result is a Number, which is the length of the argument.
58455878
When {expr} is a String or a Number the length in bytes is
58465879
used, as with |strlen()|.
@@ -5851,7 +5884,10 @@ len({expr}) The result is a Number, which is the length of the argument.
58515884
|Dictionary| is returned.
58525885
Otherwise an error is given.
58535886

5854-
*libcall()* *E364* *E368*
5887+
Can also be used as a |method|: >
5888+
mylist->len()
5889+
5890+
< *libcall()* *E364* *E368*
58555891
libcall({libname}, {funcname}, {argument})
58565892
Call function {funcname} in the run-time library {libname}
58575893
with single argument {argument}.
@@ -6136,6 +6172,8 @@ map({expr1}, {expr2}) *map()*
61366172
Funcref errors inside a function are ignored, unless it was
61376173
defined with the "abort" flag.
61386174

6175+
Can also be used as a |method|: >
6176+
mylist->map(expr2)
61396177
61406178
maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
61416179
When {dict} is omitted or zero: Return the rhs of mapping
@@ -6462,15 +6500,21 @@ max({expr}) Return the maximum value of all items in {expr}.
64626500
items in {expr} cannot be used as a Number this results in
64636501
an error. An empty |List| or |Dictionary| results in zero.
64646502

6465-
*min()*
6503+
Can also be used as a |method|: >
6504+
mylist->max()
6505+
6506+
< *min()*
64666507
min({expr}) Return the minimum value of all items in {expr}.
64676508
{expr} can be a list or a dictionary. For a dictionary,
64686509
it returns the minimum of all values in the dictionary.
64696510
If {expr} is neither a list nor a dictionary, or one of the
64706511
items in {expr} cannot be used as a Number this results in
64716512
an error. An empty |List| or |Dictionary| results in zero.
64726513

6473-
*mkdir()* *E739*
6514+
Can also be used as a |method|: >
6515+
mylist->min()
6516+
6517+
< *mkdir()* *E739*
64746518
mkdir({name} [, {path} [, {prot}]])
64756519
Create directory {name}.
64766520

@@ -7154,6 +7198,9 @@ remove({list}, {idx} [, {end}]) *remove()*
71547198
<
71557199
Use |delete()| to remove a file.
71567200

7201+
Can also be used as a |method|: >
7202+
mylist->remove(idx)
7203+
71577204
remove({blob}, {idx} [, {end}])
71587205
Without {end}: Remove the byte at {idx} from |Blob| {blob} and
71597206
return the byte.
@@ -7189,6 +7236,8 @@ repeat({expr}, {count}) *repeat()*
71897236
:let longlist = repeat(['a', 'b'], 3)
71907237
< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
71917238

7239+
Can also be used as a |method|: >
7240+
mylist->repeat(count)
71927241
71937242
resolve({filename}) *resolve()* *E655*
71947243
On MS-Windows, when {filename} is a shortcut (a .lnk file),
@@ -7206,13 +7255,15 @@ resolve({filename}) *resolve()* *E655*
72067255
current directory (provided the result is still a relative
72077256
path name) and also keeps a trailing path separator.
72087257

7209-
*reverse()*
7210-
reverse({object})
7258+
7259+
reverse({object}) *reverse()*
72117260
Reverse the order of items in {object} in-place.
72127261
{object} can be a |List| or a |Blob|.
72137262
Returns {object}.
72147263
If you want an object to remain unmodified make a copy first: >
72157264
:let revlist = reverse(copy(mylist))
7265+
< Can also be used as a |method|: >
7266+
mylist->reverse()
72167267
72177268
round({expr}) *round()*
72187269
Round off {expr} to the nearest integral value and return it
@@ -8070,7 +8121,10 @@ sort({list} [, {func} [, {dict}]]) *sort()* *E702*
80708121
on numbers, text strings will sort next to each other, in the
80718122
same order as they were originally.
80728123

8073-
Also see |uniq()|.
8124+
Can also be used as a |method|: >
8125+
mylist->sort()
8126+
8127+
< Also see |uniq()|.
80748128

80758129
Example: >
80768130
func MyCompare(i1, i2)
@@ -8378,7 +8432,10 @@ string({expr}) Return {expr} converted to a String. If {expr} is a Number,
83788432
replaced by "[...]" or "{...}". Using eval() on the result
83798433
will then fail.
83808434

8381-
Also see |strtrans()|.
8435+
Can also be used as a |method|: >
8436+
mylist->string()
8437+
8438+
< Also see |strtrans()|.
83828439

83838440
*strlen()*
83848441
strlen({expr}) The result is a Number, which is the length of the String
@@ -9000,6 +9057,9 @@ type({expr}) The result is a Number representing the type of {expr}.
90009057
< To check if the v:t_ variables exist use this: >
90019058
:if exists('v:t_number')
90029059
9060+
< Can also be used as a |method|: >
9061+
mylist->type()
9062+
90039063
undofile({name}) *undofile()*
90049064
Return the name of the undo file that would be used for a file
90059065
with name {name} when writing. This uses the 'undodir'
@@ -9064,10 +9124,15 @@ uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
90649124
< The default compare function uses the string representation of
90659125
each item. For the use of {func} and {dict} see |sort()|.
90669126

9127+
Can also be used as a |method|: >
9128+
mylist->uniq()
9129+
90679130
values({dict}) *values()*
90689131
Return a |List| with all the values of {dict}. The |List| is
90699132
in arbitrary order. Also see |items()| and |keys()|.
90709133

9134+
Can also be used as a |method|: >
9135+
mydict->values()
90719136
90729137
virtcol({expr}) *virtcol()*
90739138
The result is a Number, which is the screen column of the file

0 commit comments

Comments
 (0)