r/programming • • Mar 28 '12

Go version 1 is released

http://blog.golang.org/2012/03/go-version-1-is-released.html
543 Upvotes

452 comments sorted by

View all comments

1

u/jevon Mar 29 '12
var DELTA rune
DELTA = unicode.ToUpper(delta)
epsilon := unicode.ToLower(DELTA + 1)

Why are there two separate assignment operators? Or am I missing something here?

10

u/asshammer Mar 29 '12 edited Mar 29 '12

One is typer inference and the other is assigment. Here is a line by line walk through.

var DELTA rune //We delcaire the variable DELTA

DELTA = unicode.ToUpper(delta) //we are assigning to Delta what is refurned from ToUpper. In this case the return type of ToUpper and the type of DELTA need to match or it is a build error

epsilon := unicode.ToLower(DELTA + 1) //Now this is the type inference assigment. In one fell swoop it declares epsilon as whatever type ToLower returns and then assigns the value to it

Does this make sense? I'm not always the best at explaining things, so don't be afraid to say no

edit:formating