summaryrefslogtreecommitdiff
path: root/doc/go_tutorial.txt
diff options
context:
space:
mode:
Diffstat (limited to 'doc/go_tutorial.txt')
-rw-r--r--doc/go_tutorial.txt22
1 files changed, 14 insertions, 8 deletions
diff --git a/doc/go_tutorial.txt b/doc/go_tutorial.txt
index 9c08bd278..5eea3c980 100644
--- a/doc/go_tutorial.txt
+++ b/doc/go_tutorial.txt
@@ -189,14 +189,19 @@ started; for instance, "os.Args" is a slice used by the
An Interlude about Types
----
-Go has some familiar types such as "int" and "float", which represent
+Go has some familiar types such as "int" and "uint" (unsigned "int"), which represent
values of the ''appropriate'' size for the machine. It also defines
explicitly-sized types such as "int8", "float64", and so on, plus
-unsigned integer types such as "uint", "uint32", etc. These are
-distinct types; even if "int" and "int32" are both 32 bits in size,
+unsigned integer types such as "uint", "uint32", etc.
+These are distinct types; even if "int" and "int32" are both 32 bits in size,
they are not the same type. There is also a "byte" synonym for
"uint8", which is the element type for strings.
+Floating-point types are always sized: "float32" and "float64",
+plus "complex64" (two "float32s") and "complex128"
+(two "float64s"). Complex numbers are outside the
+scope of this tutorial.
+
Speaking of "string", that's a built-in type as well. Strings are
<i>immutable values</i>&mdash;they are not just arrays of "byte" values.
Once you've built a string <i>value</i>, you can't change it, although
@@ -362,13 +367,14 @@ language specification but here are some illustrative examples:
a := uint64(0) // equivalent; uses a "conversion"
i := 0x1234 // i gets default type: int
var j int = 1e6 // legal - 1000000 is representable in an int
- x := 1.5 // a float
+ x := 1.5 // a float64, the default type for floating constants
i3div2 := 3/2 // integer division - result is 1
- f3div2 := 3./2. // floating point division - result is 1.5
+ f3div2 := 3./2. // floating-point division - result is 1.5
Conversions only work for simple cases such as converting "ints" of one
-sign or size to another, and between "ints" and "floats", plus a few other
-simple cases. There are no automatic numeric conversions of any kind in Go,
+sign or size to another and between integers and floating-point numbers,
+plus a couple of other instances outside the scope of a tutorial.
+There are no automatic numeric conversions of any kind in Go,
other than that of making constants have concrete size and type when
assigned to a variable.
@@ -482,7 +488,7 @@ something from the directory of installed packages.
(Also, ''"file.go"'' must be compiled before we can import the
package.)
-Now we can compile and run the program:
+Now we can compile and run the program. On Unix, this would be the result:
$ 6g file.go # compile file package
$ 6g helloworld3.go # compile main package