buzz-language / buzz

👨‍🚀 buzz, A small/lightweight statically typed scripting language
https://buzz-lang.dev
MIT License
1.22k stars 34 forks source link

Immutable objects #114

Open giann opened 1 year ago

giann commented 1 year ago

Either declare an object as immutable:

immut object Point {
    int x,
    int y,
}

And/Or declare an instance as immutable:

immut Point point = Point{
    x = 10,
    y = 10,
}

point.x = 20; | -> fails

Both would allow:

And/Or declare fields as immutable #13

If we do https://github.com/buzz-language/buzz/issues/139 the keyword would need to specify mutability instead:

mut object Point {
    int x,
    int y,
}

| If we do it per instance + immutability by default we would have to say here that
| the variable is mutable and that the instance it contains is itself mutable.
| Not really elegant.
var mut Point point = Point{
    x = 10,
    y = 10,
}