2 ms·
“Let” is mutable in Basic, too, but the part of the population that is used to that is shrinking. As to short, equal length options for ‘let’ and ‘val’: one co
by Someone 7y ago
“Let” is mutable in Basic, too, but the part of the population that is used to that is shrinking.
As to short, equal length options for ‘let’ and ‘val’: one could consider using punctuation. Forth uses colons instead of ‘fun’, and I think, in a concise language, one could get used to using, say, ‘!’ for immutable and ‘~’ for mutable. Unfortunately, they aren’t easy to type. An alternative could be to always assume immutability and only use ~ in the rare cases where one needs to mutate.
So, a simple
foo = 3
or, if one wants to simplify parsing:
= foo 3
introduces a new immutable variable, and
~ foo = 3
or
~ foo 3
a mutable one. If we allow leaving out spaces:
~foo 3
that starts to look like using sigils to indicate mutable state. I think that might be a good option in a mostly immutable language.
I think I would use Forth’s colon instead of ‘=‘. That would make ‘=‘ available for equality testing, allowing us to get rid of ‘==‘.