I have found rune type in Go and have a simple question but worth an explnation.
I fount that it is an alias for int32 and purpose is to distinguish number and character values.
http://golang.org/pkg/builtin/#rune
But I am confused with the term "rune" what actually it stands for ? e.g uint == unsigned int
But I am confused with the term "rune" what actually it stands for ? e.g uint == unsigned int
Rune stands for letter. ("Runes" are the letters in a set of related alphabets known as runic alphabets, which were used to write various Germanic languages before the adoption of the Latin alphabet. [Wikipedia]).
If a variable has type rune
in Go you know it is intended to hold a unicode code point. (rune
is shorter and clearer than codepoint
). But it is technical a int32, i.e. its representation in memory is that of an int32.
In the general sense, Unicode "rune" is just a number, exactly like 64(0x40) is the number which is the code for '@' in both ASCII and Unicode.
package main
import "fmt"
func main() {
var f float64
f = 64
var b int8
b = 64
var u uint16
u = 64
var i int
i = 64
fmt.Println(f, b, u, i)
}
Output:
64 64 64 64
What this attempts to show is that [small] whole numbers (as well as such literals) are basically typeless, i.e. untyped.
Related: Rune Literals.