JSAbrahams / mamba

🐍 The Mamba programming language, because we care about safety
MIT License
88 stars 4 forks source link

Use `fin` instead of `mut` #206

Closed JSAbrahams closed 3 years ago

JSAbrahams commented 3 years ago

Current Issue

Mamba is intended to function much like Python, and be a scripting language. Therefore, users familiar with Python will typically expect that when they define a variable they can directly edit it.

High-level description of the feature

Instead of requiring that something be explicitly defined as mutable using the keyword 'mut', everything is mutable by default. Instead, like in Java, we can explicitly define something as immutable by using the keyword 'fin. Unlike Java, however, when something is 'fin' (final), it is truly immutable, and its internal fields cannot be changed. This also means that for methods which takeselfas argument, we can define self asfin` so it will never change.

This is a bit of a difficult call to make, but I believe that considering the ecosystem of Python, Mamba should be more lenient. However, this does mean that it is more likely that self will be mutable in a method, even when it shouldn't be. Originally I wanted to prevent this, and took inspiration from Rust, but I think that Rust is perhaps more strict than what we're going for. In short:

Description of potential implementation

-[ ] Drop 'mut' token -[ ] Add 'fin' token -[ ] Change behaviour in context/environment of type checker to deal with new tokens

JSAbrahams commented 3 years ago

Already implemented