Experimenting with variable reuse within declarations and its issues

To fix this I think you would need to change the rules around declarations in general.

For one you could make the colon not reach across the comma in the identifier list. And instead for example require a colon after every variable freshly declared.

That way a:, err = ...; b:, err = ... works just fine and preserves and make very clear the sanctity of := being 2 separate operators.

The main issue with making this change now is the existing code that declares multiple variables at a time.

But as a side effect if you apply the rule that any identifier followed by a : is a declaration of a new variable scoped to the statement it is in widely, then it does enable some weird usecases, like declaring a variable, taking its address and then passing it into a function in a return by pointer api call. Though whether that is desirable is up for debate as are the rules around type inference.

1 Like

Oh my god, if not for existing code and existing style choices, I would have LOVED this syntax

Though it does feel like too big of a breaking change that, even if implemented, might silently break code that shadows other declarations of the second identifier

So instead of marking which variable are Not defined, we mark those that have to be defined.

But then you would have issues with multiple definitions that are alreaydy supported a, b : int now becomes ambiguous.

Looking back up this thread, @gingerBill already responded to a similar take on syntax: Experimenting with variable reuse within declarations and its issues - #23 by gingerBill

So we might instead want to take concrete existing and/or new odin code and apply the “I can mark which should not be defined”.