const variables in Vim9

10 views
Skip to first unread message

Bram Moolenaar

unread,
Sep 25, 2020, 6:20:14 AM9/25/20
to vim...@googlegroups.com

Coming back to the discussion about how to deal with constants. I had
been trying to follow TypeScript, leading to:

let name = [] # mutable
const name = [] # name immutable, list mutable
const! name = [] # name and list immutable

This is not actually following TypeScript, since TypeScript does not
have "const!".

I found an alternative in Dart by using "final". Java also uses
"final".

let name = [] # mutable
final name = [] # name immutable, list mutable
const name = [] # name and list immutable

This is less weird, isn't it?

Even though it's not found exactly this way in another language. Dart
uses "var name = []" for mutable. We could even go that way:

var name = [] # mutable
final name = [] # name immutable, list mutable
const name = [] # name and list immutable

Thus dropping "let" in Vim9. I've been making quite a few mistakes with
"let" in Vim9, since the meaning actually differs from "let" in legacy
Vim script. I tend to accidentally use it for assignments, even though
it's actually a declaration. Perhaps it's good to make the difference
clearer by not using "let" at all? It drops the idea of following
TypeScript, but we weren't doing that 100% anyway.

--
Sometimes you can protect millions of dollars in your budget simply by buying
a bag of cookies, dropping it on the budget anylyst's desk, and saying
something deeply personal such as "How was your weekend, big guy?"
(Scott Adams - The Dilbert principle)

/// Bram Moolenaar -- Br...@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 ///
Reply all
Reply to author
Forward
0 new messages