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
Golang has integer types called byte and rune that are aliases for uint8 and int32 data types, respectively. In Go, the byte and rune data types are used to distinguish characters from integer values. In Go, there is no char data type. It uses byte and rune to represent character values.
A rune is a type meant to represent a Unicode code point. The rune type is an alias for int32 , and is used to emphasize than an integer represents a code point. ASCII defines 128 characters, identified by the code points 0–127. It covers English letters, Latin numbers, and a few other characters.
Code points, characters, and runes The Unicode standard uses the term “code point” to refer to the item represented by a single value. The code point U+2318, with hexadecimal value 2318, represents the symbol ⌘.
Go Rune Type The type rune is an alias for type int32. The rune literals are an integer value. If you store string value in rune literal, it will provide the ASCII value of the character. For example, the rune literal of 'A' will be 65.
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)
}
Playground
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With