plume-lang / plume

Plume is a lightweight programming language that aims to be portable, powerful and easy to learn.
MIT License
12 stars 2 forks source link

Mutability in Plume #2

Closed thomasvergne closed 5 months ago

thomasvergne commented 5 months ago

Bringing a brand-new mutability system to Plume based on the mut keyword. It also brings immutability by default and mutable argument passing (similar to pass-by-value and pass-by-reference).

Notable changes

Functions arguments can take a mut prefix now:

fn update<A>(mut x: A, action: fn(A): A): unit {
  x = action(*x)
}

Types can be marked as mutable:

x: mut int = 5

Plume now differentiates constant variable declarations from mutable variable declarations:

mut x = 5 // Declaring x as mutable variable with value 5
y = 6 // Declaring y as constant variable with value 6

x = 7 // Considered as variable update
y = 7 // Throws an error as y is not mutable

x = "test" // Throws an error as x is an int

Some type-checker-related limitations are present: It is impossible to generalize or declare mutable types directly bound by a for-all type variable.

It is due to issues with type inference, mutability, and soundness of the type system

Inerska commented 5 months ago

LGTM