Thursday, February 17, 2022

Re: Vim9 - Can not get compile to recognize a deep variable

> Like 'var udp: list<string>', it would be nice to declare the global
> equivalent 'g:udp: list<any>' (redundant, but reminds me what Vim is
> expecting when I look at the code).

The problem is that the type can't be enforced. In legacy script it has
always been possible to assign anything to a global variable. Also it
can be deleted with :unlet and given a completely different value.

In most cases you can use a script-local variable. In Vim9 script you
can give these a type and that will be enforced. This works best,
because references to the variable will be in the same script, the
knowledge of what the variable is for and what it's type is is
localized.

Theoretically it would be possible to add a new type of global variable
that works differently. I do not see enough need for this, while it
does add complexity. And especially that when using g:someVar you don't
know where it was defined and what kind of variable it is.

--
hundred-and-one symptoms of being an internet addict:
56. You leave the modem speaker on after connecting because you think it
sounds like the ocean wind...the perfect soundtrack for "surfing the net".

/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20220217105912.852821C0FE0%40moolenaar.net.

No comments:

Post a Comment