echo 1 == 0 # space in the beginning and end of ==
echo 1==0 # no space
can be compiled and run without warning/error
however
echo 1== 0
can be compiled and run as expected, but there is a warning ` Warning: Number of spaces around '==' is not consistent [Spacing]`
the most strange is that nim refuses to compile
echo 1 ==0
and says
Error: type mismatch: got <int literal(0)>
but expected one of:
proc `==`(x, y: float): bool
proc `==`(x, y: int64): bool
proc `==`[T](x, y: ptr T): bool
proc `==`(x, y: int): bool
proc `==`(x, y: string): bool
proc `==`[T: proc](x, y: T): bool
proc `==`[T](x, y: ref T): bool
proc `==`[T: SomeUnsignedInt](x, y: T): bool
proc `==`(x, y: bool): bool
proc `==`(x, y: char): bool
proc `==`[T](x, y: seq[T]): bool
proc `==`[T: tuple |
object](x, y: T): bool
proc `==`[Enum: enum](x, y: Enum): bool
proc `==`(x, y: float32): bool
proc `==`(x, y: int8): bool
proc `==`(x, y: int32): bool
proc `==`(x, y: int16): bool
proc `==`(x, y: cstring): bool
proc `==`[T](x, y: set[T]): bool
proc `==`(x, y: pointer): bool
proc `==`[I, T](x, y: array[I, T]): bool
expression: ==0
The warning was (controversially) added so that people don't inadvertently use prefix notation when infix was wanted like 1 ==2.
1 ==2 is parsed as (1, (==`(2)), i.e. `== is prefix while 1 == 2 is parsed as (==, 1, 2) so == is infix.
This is especially important for the operator with both prefix and infix forms like - and &.
By mistake you could use: a &b instead of a & b. More details in #7685.