> Bram Moolenaar wrote:
> > I just realized that what I mention actually would mean that the Vim9
> > behavior is wrong:
> >
> > let list = []
> > if !list
> > echo 'list is empty'
> > endif
> >
> > In legacy Vim script this gives an error, in Vim9 script it doesn't...
> > In my own defence, the legacy Vim script error is weird:
> > E745: Using a List as a Number
> >
> > Opinions?
>
>
> Personally I prefer when a language steers clear of arbitrary,
> unpredictable rules.
>
> If it were a valid construct I could only know what `if !list` does
> after consulting the language's documentation.
>
> So, I think it would be better to return a type error (hopefully saying
> "Using a List as a **Boolean**", though) and require using something like
> `if ! exists(list)` and `if ! empty(list)`.
Well, that is the main choice, either one of these:
- Require an explicit check for the list to be empty or not.
- Implicitly consider an empty list false and a non-empty list true.
Both are possible and have their advantages/disadvantages. So far I've
been mostly sticking with TypeScript, but we already agree that it
behaves unexpected in this situation (an empty list is considered true,
only a null or undefined list is false).
If we drop the idea of doing this like TypeScript, and we don't want to
make our own rules here, what other popular language could we follow?
--
Engineers will go without food and hygiene for days to solve a problem.
(Other times just because they forgot.)
(Scott Adams - The Dilbert principle)
/// Bram Moolenaar -- [email protected] -- 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 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202009251101.08PB11C0455450%40masaka.moolenaar.net.