Is there a good reason why:
var a, b = 0
works but:
var a, b: int
a, b = 0
fails?
Is it possible to assign the same value to multiple defined variable?
In the officical tutorial
Note that declaring multiple variables with a single assignment which calls a procedure can have unexpected results: the compiler will unroll the assignments and end up calling the procedure several times. If the result of the procedure depends on side effects, your variables may end up having different values! For safety use only constant values.
(https://nim-lang.org/docs/tut1.html#the-assignment-statement)
At least tuple assignment works:
var a, b, c: int
echo a, b, c
(a, b, c) = (1, 1, 1)
echo a, b, c
stefan@nuc /tmp/hhh $ ./t
000
111
And binary zero is already the default value for variables, unless {.noinit.} pragma is applied.var a, b = 0
This doesn't work the way you seem to expect it to. it only assigns zero to b and ignores a. The type of b is int the default of a which infers its type based on what is assigned/declared to its right is int and the default of int is zero. You'd have different result if you did as follows:
var a, b = 1
echo a,b
#01
The following doesn't work because you can't unpack zero.
var a, b: int
a, b = 0
On my system using Nim 0.18.0 both on Linux and Windows I get:
var a, b = 1
echo a, b
#11