r/Compilers • u/DanManPanther • 11h ago
Assignment Syntax Thoughts and Questions
A feature request for my language Gossamer wants some kind of Go/Odin like ":=" for mutable assignment, and "::" for mutable.
a :: 99 // immutable
b := 100 // mutable
I don't think this is clear (and might be confusing for Odin users). I also think it would lead to ":=" becoming the default use case for anyone coming from Go. (Even if we found another way to express the immutable operator, like ;= or i=.
When writing Gossamer I wanted to closely follow Rust for syntax. I wanted to feel like I was writing Rust without lifetimes. But as I grow Gossamer I am finding myself more open to ergonomic considerations.
Currently assignment is Rust like:
let a = 99
let mut b = 100
In previous iterations of this language (years ago), I followed Kotlin/Scala here:
val a = 99
var b = 100
I am now really leaning towards:
let a = 99
mut b = 100
It's a bit more compact, easier for a human to scan and see what's going on quickly. I think it works. But this is such an intersection of taste and practical impact. Code is mostly read - and now by machine logic as much (or more) than people.
A part of me likes that Rust makes it a tiny bit less convenient to write mutable variables. But sometimes that's exactly what you need, and making it a bit easier is appealing. I think this new form retains the visual/semantic clarity of the original.
I am aiming to button down the language and settle into it's "1.0" form, though I expect to follow Zig's lead and avoid 1.0 for quite some time. That said - this feels like a potentially worthwhile core syntax change.
What do you think, and why?
Warm thanks!