Conversation
Signed-off-by: Peter Kenny <64727695+kennypete@users.noreply.github.com>
An identical |
It fails, on this sentence:
I believe this is because |
Signed-off-by: Peter Kenny <64727695+kennypete@users.noreply.github.com>
Signed-off-by: Peter Kenny <64727695+kennypete@users.noreply.github.com>
chrisbra
left a comment
There was a problem hiding this comment.
First round of review, stopping after Variable declaration
| single character (including any composing characters) from expr10. To use | ||
| byte indexes use |strpart()|. | ||
| - Index zero gives the first byte or character. Careful: text column numbers | ||
| start with one! |
There was a problem hiding this comment.
Unless I am missing something, this describes legacy (byte) and vim9 syntax, so contrary to the In |Vim9| script: at the beginning of the paragraph.
There was a problem hiding this comment.
Not sure whether you mean strpart() or the next bullet's "Index zero...". For strpart(), no:
For "Index zero...", yes - I should have picked that (and the next one) up. Will update it to:
- Index zero gives the first character (including any composing character).
Careful: text column numbers start with one!
| - If the length of the String is less than the index, the result is an empty | ||
| String. A negative index always results in an empty string (reason: | ||
| backward compatibility). Use [-1:] to get the last byte or character. | ||
| - A negative index is used like with a list: count from the end. |
There was a problem hiding this comment.
Yes, it should be:
Use [-1 :] to get the last character (including
any composing character).
(It was missing the space before the ] too.)
| byte indexes use |strpart()|. | ||
| - Index zero gives the first byte or character. Careful: text column numbers | ||
| start with one! | ||
| - If the length of the String is less than the index, the result is an empty |
There was a problem hiding this comment.
Is this a duplicate? These lines all overlap with the two comments' lines above.
| backward compatibility). Use [-1:] to get the last byte or character. | ||
| - A negative index is used like with a list: count from the end. | ||
| - Attempting to assign to or modify a string with an index within a `:def` | ||
| function gives |E1148|. |
There was a problem hiding this comment.
but this seems to be Vim9 specific
| var ad = {item: 'value', func: DictFunc} | ||
| ad.func(ad, 'item') | ||
| < | ||
| Further, if the functions, above, are subsequently called before the functions |
There was a problem hiding this comment.
| Further, if the functions, above, are subsequently called before the functions | |
| Further, if the functions, above, are subsequently called before the commands |
in the sections around it , we use "commands" when describing DefinedLate1 and DefinedLate2
There was a problem hiding this comment.
Yes, good spot. I'll fix that with the next commit.
| enddef | ||
| MyFunc(v:none, 'LAST') # first argument uses default value 'one' | ||
| echo F(2.0, v:none) # 12.56 (using default 'pi' value, 3.14) |
There was a problem hiding this comment.
I think it is better to re-order the arguments, otherwise the use of v:none looks a bit artificial (as last argument and could be left away), so use this:
vim9script
def F(pi: float = 3.14, ra: float = 3.0): float
return pi * ra->pow(2)
enddef
echo F(v:none, 2.0) # 12.56 (using default 'pi' value, 3.14)
There was a problem hiding this comment.
Fair. I wonder about defaulting ra, though overall that's a better example for v:none.
| echo (Function(), Funcref()) # ('two', 'two') | ||
| < | ||
| Note: This persistent behavior of |funcref()| may be regarded as | ||
| either a feature, or, if not understood, be unexpected. |
There was a problem hiding this comment.
this sounds slightly odd, perhaps better:
Note: This persistent behavior of |funcref()| may be regarded as a feature, or may be unexpected if not understood.
There was a problem hiding this comment.
Sure, that flows better.
chrisbra
left a comment
There was a problem hiding this comment.
great re-work. That must have been a lot of work. Thanks
| You cannot use `:va` to declare a variable - it must be `:var`. Similarly, | ||
| you cannot use `:cons` or `:fin` for constants - they must be written in full | ||
| as `:const` or `:final`, which improves readability. Attempting to use `:va`, | ||
| `:cons`, or `:fina` gives |E1065|. |
There was a problem hiding this comment.
this is duplicate to the block above at :h vim9-declaration
| echo $'Digit {d} is "{m}" in Māori.' | ||
| < | ||
| This approach should be used only where there is a list with values. | ||
| Declaring one variable per line usually is easier to read and change later. |
There was a problem hiding this comment.
| Declaring one variable per line usually is easier to read and change later. | |
| Declaring one variable per line usually is easier to understand. |
| NAMES[1][0] = "Emma" # OK, now females[0] == "Emma" | ||
| The following script shows: | ||
| - That a constant must have a value, otherwise E1021 is given, and | ||
| - Attempts to change a constant fail, with E1307 given. |
There was a problem hiding this comment.
| - Attempts to change a constant fail, with E1307 given. | |
| - Attempts to change a constant fail, with E1307. |
| < *vim9-no-shadowing* | ||
| Variables, functions and function arguments cannot shadow previously defined | ||
| or imported variables and functions in the same script file. However, | ||
| variables can shadow Ex commands, though rename the variable if necessary. |
There was a problem hiding this comment.
| variables can shadow Ex commands, though rename the variable if necessary. | |
| variables can shadow Ex commands, so rename the variable if necessary. |
| >vim9 | ||
| vim9script | ||
| # Synonymous with ":glob/delimiter)" (and prints these lines) | ||
| :glob(delimiter) |
There was a problem hiding this comment.
I understand the point your are making here, but the command will throw an error "Pattern not found", unless you want to search for the delimiter) (including the closing paren)
| MyN( 4, 5, 6 ) # [4, 5, 6] | ||
| MyN (7, 8, 9) # E492: Not an editor command | ||
| < | ||
| Note: The following also are not allowed, and would give |E492|: > |
There was a problem hiding this comment.
| Note: The following also are not allowed, and would give |E492|: > | |
| Note: The following are also not allowed, and give |E492|: > |
There was a problem hiding this comment.
the reason why silent is allowed , is because it allows to swallow error messages when Vim does not support the eval feature, see e.g. defaults.vim
(not sure if you want to add this as an explanation)



vim9.txt: Conclusion to the rewrite and enhancements - part 2 of 2 (summary)
This is a very significant update. Initially it considered only Section 2, the last to be enhanced with sourceable Vim9 script examples. Along the way it extended to also include several standardisation changes, plus improvements to some passages of sections 4 and 6 especially. “Part 1” of the rewrite addressed those things in Sections 1, and 3 to 7 (NB: they are listed in the explanation to PR20706).
The description, which follows, is a SUMMARY only.
For more details and the rationale of changes, refer to this Gist: vim9.txt rewrite Section 2 (details).
Some improvements in this “Part 2” update necessarily involve the help files
eval.txtanduserfunc.txt, where some tags are better relocated either to/fromvim9.txt.Locations of changes are indicated by reference to *tag* in the updated file.
1. Corrections to the current help
:&: currently, the help states this, “cannot be used to repeat a:substitutecommand”. That is incorrect. Only bare&is unusable;:&remains valid.1is not literallytrue, and legacy Vim script returns1.null_partialisv:t_func, notv:t_partial.2. Error codes
Many are relocated, and almost all are accompanied by sourceable scripts now.
*vim9-comparators*), E1094, E1053, E1071, E1257, E1261, and the E1047–E1262 import/namespace block (12 errors, itemised individually via the companion “Part 1” PR).3. Other improvements
*vim9-invalid-Ex-commands*,*vim9-no-shorten*,*vim9-functions*,*vim9-any-type*,*vim9-block*,*vim9-no-shadowing*,*vim9-omitting-:call*,*vim9-omitting-:eval*,*vim9-noclear*, and more.type()/typename()/string()per value) rather than prose.4. Open questions
userfunc.txt: The recommendation to prefix autoloaded function calls withg:filename#funcname()appears worthy of revision, though is out of this PR’s scope to change.null_class/null_enumvalue: The former always errors when used as a value with no apparent legitimate use. Conversely, there is nonull_enumvalue, despite it seeming as though it could have real utility. It may be worth a design discussion.is/==non-transitivity (v:true == 8and8 == 8.0both work, butv:true == 8.0errors). This has been documented as an aside because it is outside this PR’s scope to resolve (and given it is in legacy Vim script, probably is not worth messing with, though may be worth considering).