Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This code is illegal in Go

    item := item
    item := item
"no new variables on left side of :="

You can't declare the same variable twice in the same scope.

    item := item
works only because it declares a new variable in the current scope, initialized with a variable with the same name (but different variable) from the outer scope.

Go distinguishes declarations from assignments. In this example, the second assignment is a no-op indeed.

    item := item
    item = item


Okay fair enough, thx for the explanation. Doesn't make it good, but better!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: