Skip to content

Multiple Assignment with one declared, one undeclared variable #959

Answered by gingerBill
ruipsrosario asked this question in Q&A
Discussion options

You must be logged in to vote

TL;DR This is by design and not a mistake.

:= Is actually : = with the type missing. So what you are doing is double declaration that variable.

// These three are equivalent in semantics
x: int; x = 123;
x: int = 123;
x := 123;

If you do have a "tuple" value on the right hand side, you either have to predeclare all the variables or remove the type (or specify the type if they are all of the same type). Tuples are not a first class type in this language and this is by design. I've found that tuples are only ever useful as return values from procedures and a named membered record is a much better thing to have (even if it is a little more verbose).

In Go, := is called a short variable decl…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ThisDevDane
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #29 on May 12, 2021 22:56.