Fix: can add the new value to "a:" dict#3929
Conversation
| func s:set_arg9(a) abort | ||
| let a:['b'] = 1 | ||
| endfunction | ||
|
|
There was a problem hiding this comment.
please add
function s:set_arg10(...) abort
let a:000[0][0] = 1
endfunction
call s:set_arg10([0])There was a problem hiding this comment.
Thank you. I added Test_let_varg_fail() for that.
Codecov Report
@@ Coverage Diff @@
## master #3929 +/- ##
==========================================
+ Coverage 78.84% 78.85% +<.01%
==========================================
Files 105 105
Lines 142076 142078 +2
==========================================
+ Hits 112024 112030 +6
+ Misses 30052 30048 -4
Continue to review full report at Codecov.
|
|
Would it be possible to leave this behavior enabled, and to change the documentation instead? Removing the ability to declare variables in the ""
" @function Foo([bar] [quo])
" @default bar='bar'
" @default quo=2
function! Foo(...) abort
let a:bar = get(a:000, 0, 'bar')
let a:quo = get(a:000, 1, 2)
" ...
endfunctionIn a future refactoring, this could be easily changed to: function! Foo(bar, quo) abort
" ...Without needing to find-and-replace Using the |
|
I don't think that it's good way. Documentation says
function s:foo(b)
let a:b = 1 " ERROR
let a:c = 1 " NOT ERROR
endfunctionWe can not make documentation correct and non-contradictory if it allow to change. |
|
I'd like to say that the old behavior is inconsistent as @mattn shows in the example. |
|
Would it be possible to leave this behavior enabled, and to change the
documentation instead? Removing the ability to declare variables in
the `a:` namespace eliminates what is (IMO) a clean and idiomatic way
to use "default arguments" in VimL functions:
```vim
""
" @function Foo([bar] [quo])
" @default bar='bar'
" @default quo=2
function! Foo(...) abort
let a:bar = get(a:000, 0, 'bar')
let a:quo = get(a:000, 1, 2)
" ...
endfunction
```
In a future refactoring, this could be easily changed to:
```vim
function! Foo(bar, quo) abort
" ...
```
Without needing to find-and-replace `l:bar` with `a:bar`, etc. in the
function body.
Using the `l:` scope definitely wouldn't be a huge inconvenience, but
I feel that explicitly declaring variables in the `a:` namespace is
better at communicating intent. It's something that I use in [my own
plugins,](https://github.com/Yilin-Yang/TypeVim/blob/4b75041aad7de2bf4121679a7631f51c1bc3b657/autoload/typevim/object.vim#L519)
at the very least, though the only other plugins I've found that do
this declare inside of the `l:` scope instead (e.g.
[LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim/blob/8eba06bf6540915deeae7da9b239f0f918e20cd9/autoload/LanguageClient.vim#L515),
[ALE](https://github.com/w0rp/ale/blob/bf196ba17c9e261e4e3a9dba64260c6d0b2c8af9/autoload/ale.vim#L120)).
It's a basic principle that arguments don't change. It helps a lot for
debugging, since you can rely on the a: dict not to have changed
somewhere.
For optional arguments it's better to follow what most other languages
do:
func Foo(must_have, optional = value)
Thus optional arguments always have a default value. That avoids having
to check for whether they are present or not.
It would also be possible to allow specifying the argument name in the call:
func Foo(must_have, optional = value, also_optional = '')
call Foo('must', also_optional = 'there')
However, it has the disadvantage that changing the argument name in the
function definition requires all calls to be changed, and one doesn't
always know what calls use the name, which leads to mistakes. Just
using positional arguments is simpler. One can pass a dictionary to
have a bunch of optional arguments (as many built-in functions already
do).
…--
Wi n0t trei a h0liday in Sweden thi yer?
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
|
On 2/12/19 3:47 PM, Bram Moolenaar (Vim Github Repository) wrote:
> Would it be possible to leave this behavior enabled, and to change the
> documentation instead? Removing the ability to declare variables in
> the `a:` namespace eliminates what is (IMO) a clean and idiomatic way
> to use "default arguments" in VimL functions:
>
> ```vim
> ""
> " @function Foo([bar] [quo])
> " @default bar='bar'
> " @default quo=2
> function! Foo(...) abort
> let a:bar = get(a:000, 0, 'bar')
> let a:quo = get(a:000, 1, 2)
> " ...
> endfunction
> ```
>
> In a future refactoring, this could be easily changed to:
> ```vim
> function! Foo(bar, quo) abort
> " ...
> ```
> Without needing to find-and-replace `l:bar` with `a:bar`, etc. in the
> function body.
>
> Using the `l:` scope definitely wouldn't be a huge inconvenience, but
> I feel that explicitly declaring variables in the `a:` namespace is
> better at communicating intent. It's something that I use in [my own
>
plugins,](https://github.com/Yilin-Yang/TypeVim/blob/4b75041aad7de2bf4121679a7631f51c1bc3b657/autoload/typevim/object.vim#L519)
> at the very least, though the only other plugins I've found that do
> this declare inside of the `l:` scope instead (e.g.
>
[LanguageClient-neovim](https://github.com/autozimu/LanguageClient-neovim/blob/8eba06bf6540915deeae7da9b239f0f918e20cd9/autoload/LanguageClient.vim#L515),
>
[ALE](https://github.com/w0rp/ale/blob/bf196ba17c9e261e4e3a9dba64260c6d0b2c8af9/autoload/ale.vim#L120)).
It's a basic principle that arguments don't change. It helps a lot for
debugging, since you can rely on the a: dict not to have changed
somewhere.
For optional arguments it's better to follow what most other languages
do:
func Foo(must_have, optional = value)
Thus optional arguments always have a default value. That avoids having
to check for whether they are present or not.
It would also be possible to allow specifying the argument name in the
call:
func Foo(must_have, optional = value, also_optional = '')
call Foo('must', also_optional = 'there')
However, it has the disadvantage that changing the argument name in the
function definition requires all calls to be changed, and one doesn't
always know what calls use the name, which leads to mistakes. Just
using positional arguments is simpler. One can pass a dictionary to
have a bunch of optional arguments (as many built-in functions already
do).
--
Wi n0t trei a h0liday in Sweden thi yer?
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#3929 (comment)>
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google
Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to ***@***.***
***@***.***>.
For more options, visit https://groups.google.com/d/optout.
I wonder, should default argument expressions be parsed once at
definition (like python) or every time at call (like ruby)?
i.e., I assume this should be permitted: func Foo(must_have, optional =
a:must_have)
but of course, this should not: func Foo(may_have = a:second, second = 1)
|
|
I wonder, should default argument expressions be parsed once at
definition (like python) or every time at call (like ruby)?
i.e., I assume this should be permitted: func Foo(must_have, optional =
a:must_have)
but of course, this should not: func Foo(may_have = a:second, second = 1)
Python's way of doing this very often leads to mistakes.
You cannot refer to other a: variables for the default value expression.
It is evaluated before the a: dict is filled.
…--
People who want to share their religious views with you
almost never want you to share yours with them.
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
This fixes an issue with Vim 8.1.0887 and newer. When a change is landed, then revert back to canonical repo. Issue: chriskempson/base16-vim#197 Pull Request: chriskempson/base16-vim#198 More info: vim/vim#3929 Signed-off-by: Fletcher Nichol <fnichol@nichol.ca>
Issue: chriskempson/base16-vim#197 Pull Request: chriskempson/base16-vim#198 More info: vim/vim#3929
Issue: chriskempson/base16-vim#197 Pull Request: chriskempson/base16-vim#198 More info: vim/vim#3929
Issue: chriskempson/base16-vim#197 Pull Request: chriskempson/base16-vim#198 More info: vim/vim#3929
Problem: The a: dict is not immutable as documented.
Solution: Make the a:dict immutable, add a test. (Ozaki Kiichi, Yasuhiro
Matsumoto, closes vim/vim#3929)
vim/vim@31b8160
Problem: The a: dict is not immutable as documented.
Solution: Make the a:dict immutable, add a test. (Ozaki Kiichi, Yasuhiro
Matsumoto, closes vim/vim#3929)
vim/vim@31b8160
Problem: The a: dict is not immutable as documented.
Solution: Make the a:dict immutable, add a test. (Ozaki Kiichi, Yasuhiro
Matsumoto, closes vim/vim#3929)
vim/vim@31b8160
Problem: The a: dict is not immutable as documented.
Solution: Make the a:dict immutable, add a test. (Ozaki Kiichi, Yasuhiro
Matsumoto, closes vim/vim#3929)
vim/vim@31b8160
fe0359761 Dependency updates c3ef7a77c Greenkeeper/default/husky 3.0.9 (#189) 2986331de fix typo (#185) 43986d71c Greenkeeper/default/husky 3.0.7 (#183) a9225db0f chore(package): update husky to version 3.0.4 (#179) af3c27193 Stop using doT for templating; dependency updates 4d28b36e8 Update husky in group default to the latest version 🚀 (#172) 904922988 Dependency updates 8bc66ee25 chore(package): update eslint to version 6.0.0 (#171) ef4a37a95 Adjust go highlighting (#170) 91128e181 Update dependencies 63b69b9f6 Fix alacritty cursor colors configuration. 7f36f83f1 Add specifics highlights for Go (#165) 782c195ac Update husky in group default to the latest version 🚀 (#163) d8d5f7fe7 Use higher-resolution color reference image. 7c30d3e4d Add color reference image. 723c616d4 Remove stray comment character ca2ae4d6d Added support for .tex files (#159) 36304e9b5 Don't peg package versions to reduce frequency of Greenkeeper updates 7b3229eec Don't peg verisons to reduce frequency of greenkeeper updates d32314d4a Update eslint in group default to the latest version 🚀 (#156) 9cd544f0f Update eslint in group default to the latest version 🚀 (#155) 07f6e3426 Update eslint in group default to the latest version 🚀 (#154) d1ada870e Update eslint in group default to the latest version 🚀 (#153) 205f57702 Update eslint in group default to the latest version 🚀 (#150) f65e71f25 Update eslint in group default to the latest version 🚀 (#149) a570035f4 README.md: Fix typo 04ba47974 Don't write to the "a:" dict per vim/vim#3929 . 2e817f0dd Update eslint in group default to the latest version 🚀 (#147) 4bf689976 Update eslint in group default to the latest version 🚀 (#146) 06bf8fa3b README.md: Fix a typo 682f86676 Add troubleshooting note about iTerm2. 598d37272 README.md: Better Greenkeeper badge placement 6b86d7861 Cleanup from initial Greenkeeper PR 4d342c91a Update dependencies to enable Greenkeeper 🌴 (#143) 438369790 Add :Termdebug highlight groups. fbf5af495 Tweak and document g:onedark_hide_endofbuffer 62bcd5ffb Add optional setting for end-of-buffer tildes (#142) a6325876f Fix usage of doT in build system 173a4df76 Oopsie. 5923008ce Hopefully fix CircleCI config dc8431c1a Add CircleCI 6d96889eb Added terminal statusbar highlight group (#138) 77c7b00eb Add a tweak for fish shell scripts (#135) 2a6155a25 Update README 7e03caaaf Add alacritty support (#132) 07ff25c34 Add terminal colors. cabf8e6df Fancy header image for README 6e219a958 Revise DiffChange/DiffText to be less ambiguous and less visually loud. a24854a55 README.md: Add drewtempelmeyer/palenight.vim to the "Relatives of onedark.vim" list 8ef6341ba Update build dependencies 4f0292533 Add plugin highlighting for easymotion/vim-easymotion. Closes #116. 8b5544e29 Enhance the implementation of onedark#extend_highlight and improve the README 62f84d27c Merge branch 'kristijanhusak-feature/extend-highlight-group' 88b7d3430 Nitpicky tweaks 3eb31282e Expose function for extending highlight group. d75941397 README.md: Fix formatting; add note about installation as a Vim 8 package. Closes #110 1552d3e8e In diff mode, for cursorline, use underline styling instead of background styling to improve readability. git-subtree-dir: bundle/onedark.vim git-subtree-split: fe035976117ba5c2481df3b2cad3bb0a8b045b9f
Currently we can add the new key-value to "a:" dict.
NOTE: A part of the tests is based on @mattn's code.