Mercurial > vim
comparison runtime/doc/vim9.txt @ 19904:bd4f91762d0f v8.2.0508
patch 8.2.0508: Vim9: func and partial types not done yet
Commit: https://github.com/vim/vim/commit/d77a8525d5438cae49f670eb473ef60d87ca5f54
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Apr 3 21:59:57 2020 +0200
patch 8.2.0508: Vim9: func and partial types not done yet
Problem: Vim9: func and partial types not done yet
Solution: Fill in details about func declaration, drop a separate partial
declaration.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 03 Apr 2020 22:15:03 +0200 |
parents | 847a300aa244 |
children | 1908e92b02fd |
comparison
equal
deleted
inserted
replaced
19903:dab021621df2 | 19904:bd4f91762d0f |
---|---|
1 *vim9.txt* For Vim version 8.2. Last change: 2020 Mar 01 | 1 *vim9.txt* For Vim version 8.2. Last change: 2020 Apr 03 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
247 :def[!] {name}([arguments])[: {return-type} | 247 :def[!] {name}([arguments])[: {return-type} |
248 Define a new function by the name {name}. The body of | 248 Define a new function by the name {name}. The body of |
249 the function follows in the next lines, until the | 249 the function follows in the next lines, until the |
250 matching `:enddef`. | 250 matching `:enddef`. |
251 | 251 |
252 When {return-type} is omitted the function is not | 252 When {return-type} is omitted or is "void" the |
253 expected to return anything. | 253 function is not expected to return anything. |
254 | 254 |
255 {arguments} is a sequence of zero or more argument | 255 {arguments} is a sequence of zero or more argument |
256 declarations. There are three forms: | 256 declarations. There are three forms: |
257 {name}: {type} | 257 {name}: {type} |
258 {name} = {value} | 258 {name} = {value} |
294 bool | 294 bool |
295 number | 295 number |
296 float | 296 float |
297 string | 297 string |
298 blob | 298 blob |
299 list<type> | 299 list<{type}> |
300 dict<type> | 300 dict<{type}> |
301 (a: type, b: type): type | |
302 job | 301 job |
303 channel | 302 channel |
304 func | 303 func |
305 partial | 304 func({type}, ...) |
305 func({type}, ...): {type} | |
306 | 306 |
307 Not supported yet: | 307 Not supported yet: |
308 tuple<a: type, b: type, ...> | 308 tuple<a: {type}, b: {type}, ...> |
309 | 309 |
310 These types can be used in declarations, but no variable will have this type: | 310 These types can be used in declarations, but no value will have this type: |
311 type|type | 311 {type}|{type} |
312 void | 312 void |
313 any | 313 any |
314 | 314 |
315 There is no array type, use list<type> instead. For a list constant an | 315 There is no array type, use list<{type}> instead. For a list constant an |
316 efficient implementation is used that avoids allocating lot of small pieces of | 316 efficient implementation is used that avoids allocating lot of small pieces of |
317 memory. | 317 memory. |
318 | 318 |
319 A function defined with `:def` must declare the return type. If there is no | 319 A partial and function can be declared in more or less specific ways: |
320 type then the function doesn't return anything. "void" is used in type | 320 func any kind of function reference, no type |
321 declarations. | 321 checking |
322 func: {type} any number and type of arguments with specific | |
323 return type | |
324 func({type} ...) function with argument types, does not return | |
325 a value | |
326 func({type} ...): {type} function with argument types and return type | |
327 | |
328 If the return type is "void" the function does not return a value. | |
329 | |
330 The reference can also be a |Partial|, in which case it stores extra arguments | |
331 and/or a dictionary, which are not visible to the caller. Since they are | |
332 called in the same way the declaration is the same. | |
322 | 333 |
323 Custom types can be defined with `:type`: > | 334 Custom types can be defined with `:type`: > |
324 :type MyList list<string> | 335 :type MyList list<string> |
325 {not implemented yet} | 336 {not implemented yet} |
326 | 337 |