Hacker News new | past | comments | ask | show | jobs | submit login

The := both declares a new variable by an inferred type and assigns a value to it. Explicitly, this would be the same as

  var item *Item = item
It creates a locally scoped variable that shadows the existing one.



Ah ok, so different name resolution rules apply on the left and right sides of the operator?

On the left side, "item" resolves to the "item" in inner scope (that is declared on the same line). On the right side it resolves to the "item" in outer scope.

Then I understand what's happening though I'm still not convinced it's sane behaviour. I would expect all identical names in a single scope to refer to the same variable.




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

Search: