From 758ff64c69e34965f8af5b2d6ffd65e8d7ab2150 Mon Sep 17 00:00:00 2001 From: Ondřej Surý Date: Mon, 14 Feb 2011 13:23:51 +0100 Subject: Imported Upstream version 2011-02-01.1 --- doc/go_tutorial.html | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'doc/go_tutorial.html') diff --git a/doc/go_tutorial.html b/doc/go_tutorial.html index 11e9b4ad7..ece22036a 100644 --- a/doc/go_tutorial.html +++ b/doc/go_tutorial.html @@ -238,14 +238,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 immutable values—they are not just arrays of byte values. Once you've built a string value, you can't change it, although @@ -452,14 +457,15 @@ 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.

@@ -538,9 +544,9 @@ We can use the factory to construct some familiar, exported variables of type

 
 24    var (
-25        Stdin  = newFile(0, "/dev/stdin")
-26        Stdout = newFile(1, "/dev/stdout")
-27        Stderr = newFile(2, "/dev/stderr")
+25        Stdin  = newFile(syscall.Stdin, "/dev/stdin")
+26        Stdout = newFile(syscall.Stdout, "/dev/stdout")
+27        Stderr = newFile(syscall.Stderr, "/dev/stderr")
 28    )
 

@@ -663,7 +669,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
-- 
cgit v1.2.3