Related to an issue (https://github.com/nim-lang/Nim/issues/4067) I opened about an unhelpful error message, I'd like to ask here why 'var' is before a variable but after a proc parameter, from a grammar/design view?
var p: int versus proc doSomethingToP(p: var int)...
Clearer semantics from syntax?
var p: int
declares a variable named p of type int. While p in:
proc doSomethingToP(p: var int)
declares a parameter named p of type modifiable int. It's like tying parameter passing as part of the parameter type. AFAICS, there should be no noticable difference in grammar/design/parsing view of such a syntax.
In Modula 2 and OBERON we had
proc doSomethingToP(var p: int)
so var in front of the identifier tells us that it can be modified. I was always happy with that notation -- in Nim I did it the old way a few times. but now I generally can remember it. Maybe the Nim notation is indead more clear because the name of the variable resides at the left, not in the middle of var keyword and type.