In both cases, Go and Python, the operator will assign a variable a value and also use it as an expression.
That is absolutely not true. foo := <expr>
is a statement in Go, full stop. Just try something trivial like assigning to the output of :=
: https://go.dev/play/p/nPINGc7LO8B
It’s true that if
and for
let you use :=
but don’t let you use var
, but you still can’t use the result of the assignment directly. So for instance you need if foo := <expr>; foo { ... }
rather than just if foo := <expr> { ... }
.
How does the
const { None }
example type-inference work? The size of the option type can’t be known without knowing the type of theSome
variant.Edit: aha, it doesn’t work as-is. It needs to infer the type of elements of
foo
from usage. https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=05a95c592626b6935ae812527aa6bbc6