-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathClosure.txt
221 lines (167 loc) · 8.04 KB
/
Closure.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
*vital/Data/Closure.txt* Provide Closure object.
Maintainer: thinca <[email protected]>
==============================================================================
CONTENTS *Vital.Data.Closure-contents*
INTRODUCTION |Vital.Data.Closure-introduction|
INTERFACE |Vital.Data.Closure-interface|
FUNCTIONS |Vital.Data.Closure-functions|
OBJECTS |Vital.Data.Closure-objects|
Closure Object |Vital.Data.Closure-Closure|
==============================================================================
INTRODUCTION *Vital.Data.Closure-introduction*
*Vital.Data.Closure* provides Closure object.
>
let C = vital#{plugin-name}#new().import('Data.Closure')
<
==============================================================================
TERM *Vital.Data.Closure-term*
{callable} *Vital.Data.Closure-term-callable*
A {callable} is one of the followings.
- A |Funcref|
- |Vital.Data.Closure.from_funcref()|
- A string of function name which begins from "*"
- |Vital.Data.Closure.from_funcname()|
- An ex command string which begins from ":"
- |Vital.Data.Closure.from_command()|
- A |List| of ex command strings which begin from ":"
- |Vital.Data.Closure.from_command()|
- An operator string such as '+', '%', or '=~#'
- |Vital.Data.Closure.from_operator()|
- An |expr| string which begins from "="
- |Vital.Data.Closure.from_expr()|
- A Closure object(|Vital.Data.Closure-Closure|)
- A |List| that is arguments of |Vital.Data.Closure.build()|.
{arglist} *Vital.Data.Closure-term-arglist*
This is a |List| for the arguments of the function.
{args}... *Vital.Data.Closure-term-args*
This is variadic for the function.
{context} *Vital.Data.Closure-term-context*
This is a |Dictionary| that is treated as |self| of {function}.
{binding} *Vital.Data.Closure-term-binding*
{binding} is a |Dictionary|. You can access to this Dictionary from
{expr} or {command} as local variables.
Note that the key for |Funcref| must start with a capital.
When {binding} is a |List| of |Dictionary|, a new |Dictionary| will be
created as new {binding}, and all dictionaries are extended to the new
dictionary.
If local variable is changed, {binding} will change similarly. This
feature is available in Vim 7.3.560 or later.
==============================================================================
INTERFACE *Vital.Data.Closure-interface*
------------------------------------------------------------------------------
FUNCTIONS *Vital.Data.Closure-functions*
*Vital.Data.Closure.build()*
build({callable} [, {arglist}][, {context}])
Builds a Closure object(|Vital.Data.Closure-Closure|) from {callable}.
It is {arglist} when the second argument or subsequent ones is a list.
It is {context} when the second argument or subsequent ones is a
dictionary.
See |Vital.Data.Closure-Closure| for detail of {arglist} and
{context}.
call({callable}, {args}...) *Vital.Data.Closure.call()*
Shortcut version of |Vital.Data.Closure.apply()|.
{args}... is treated as {arglist}.
*Vital.Data.Closure.apply()*
apply({callable} [, {arglist}][, {context}])
Builds a Closure object by |Vital.Data.Closure.build()| and calls it.
See |Vital.Data.Closure.build()| for detail of arguments.
*Vital.Data.Closure.from_funcref()*
from_funcref({funcref} [, {arglist}][, {context}])
Builds a Closure object from {funcref}.
See |Vital.Data.Closure-Closure| for detail of {arglist} and
{context}.
*Vital.Data.Closure.from_funcname()*
from_funcname({funcname} [, {arglist}][, {context}])
Builds a Closure object from {funcname}.
There may be "*" prefix in {funcname}.
{funcname} is a builtin function or global function.
See |Vital.Data.Closure-Closure| for detail of {arglist} and
{context}.
from_expr({expr} [, {binding}]) *Vital.Data.Closure.from_expr()*
Builds a Closure object from {expr} string.
There may be "=" prefix in {expr}.
You can use |a:| as the arguments.
See |Vital.Data.Closure-term-binding| about {binding}.
from_command({command} [, {binding}]) *Vital.Data.Closure.from_command()*
Builds a Closure object from {command}.
{command} is a String or a List of strings.
You can use |a:| as the arguments.
See |Vital.Data.Closure-term-binding| about {binding}.
from_operator({operator}) *Vital.Data.Closure.from_operator()*
Builds a Closure object from {operator}.
{operator} is an operator string such as '+', '%', or '=~#'
from_method({object}, {method}) *Vital.Data.Closure.from_method()*
Builds a Closure object from {object}(Dictionary) and the name of
{method}.
compose({callables}) *Vital.Data.Closure.compose()*
Builds a new composed Closure objects from {callables}.
{callables} is a List of callable(|Vital.Data.Closure-term-callable|).
For example, there are the functions named "F", "G", "H":
>
compose(['*F', '*G', '*H']).call({args}) == F(G(H({args})))
<
Other example:
>
let sortuniq = C.compose(['*uniq', '*sort'])
echo sortuniq.call([2, 4, 2, 1, 3, 4, 5, 1, 5, 3])
" => [1, 2, 3, 4, 5]
is_closure({expr}) *Vital.Data.Closure.is_closure()*
Returns true when the {expr} is a Closure object.
is_callable({expr}) *Vital.Data.Closure.is_callable()*
Returns true when the {expr} is callable.
See also |Vital.Data.Closure-term-callable|.
sweep_functions() *Vital.Data.Closure.sweep_functions()*
Sweeps garbage functions.
|Vital.Data.Closure-Closure.to_function()| with {limit} creates a
function, but can not delete the function itself.
As a result, the function remains as garbage.
This function sweeps it.
This is automatically called by |Vital.Data.Closure.build()|.
is_binding_supported() *Vital.Data.Closure.is_binding_supported()*
Returns true when the {binding} feature supports local changing.
See also |Vital.Data.Closure-term-binding|.
==============================================================================
OBJECTS *Vital.Data.Closure-objects*
------------------------------------------------------------------------------
Closure Object *Vital.Data.Closure-Closure*
A Closure object has following members.
- function(|Funcref|)
- arglist(|Vital.Data.Closure-term-arglist|)
- Part of head of arguments.
- context(|Vital.Data.Closure-term-context|)
Closure object can call the {function} with {arglist}, and with {context}.
Example: >
let closure = C.from_funcname('strftime', ['%Y%m%d'])
echo closure.call(1412686257)
Closure.call({args}...) *Vital.Data.Closure-Closure.call()*
Shortcut version of |Vital.Data.Closure-Closure.apply()|.
{args}... is treated as {arglist}.
Closure.apply({arglist}) *Vital.Data.Closure-Closure.apply()*
Calls this Closure object with {arglist}.
Closure.with_args({args}...) *Vital.Data.Closure-Closure.with_args()*
Shortcut version of |Vital.Data.Closure-Closure.with_arglist()|.
{args}... is treated as {arglist}.
Closure.with_arglist({arglist}) *Vital.Data.Closure-Closure.with_arglist()*
Creates a new Closure object which has the {arglist}.
{arglist} is appended to the existing arglist.
>
let get_win_var = C.from_funcname('getwinvar')
let get_current_win_var = get_win_var.with_arglist([0])
let get_current_win_scope = get_current_win_var.with_arglist([''])
echo get_current_win_scope.call() is getwinvar(0, '')
Closure.with_context({context}) *Vital.Data.Closure-Closure.with_context()*
Creates a new Closure object which has the {context}.
{context} is replaced by the argument.
Closure.compose({callable}) *Vital.Data.Closure-Closure.compose()*
Same as `C.compose([{callable}, self])`.
See also |Vital.Data.Closure.compose()|.
Closure.to_function([{limit}]) *Vital.Data.Closure-Closure.to_function()*
Defines a new function for this closure and return its |Funcref|.
Note that the function remains after this closure was deleted.
When the {limit} is supplied, the function will be marked as delete
after the function is called {limit} times.
See also |Vital.Data.Closure.sweep_functions()|.
Closure.delete_function() *Vital.Data.Closure-Closure.delete_function()*
Deletes the function made by |Vital.Data.Closure-Closure.to_function()|.
==============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl