summaryrefslogtreecommitdiff
path: root/doc/go_tutorial.html
diff options
context:
space:
mode:
Diffstat (limited to 'doc/go_tutorial.html')
-rw-r--r--doc/go_tutorial.html28
1 files changed, 17 insertions, 11 deletions
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, <code>os.Args</code> is a slice used by the
<p>
<h2>An Interlude about Types</h2>
<p>
-Go has some familiar types such as <code>int</code> and <code>float</code>, which represent
+Go has some familiar types such as <code>int</code> and <code>uint</code> (unsigned <code>int</code>), which represent
values of the ''appropriate'' size for the machine. It also defines
explicitly-sized types such as <code>int8</code>, <code>float64</code>, and so on, plus
-unsigned integer types such as <code>uint</code>, <code>uint32</code>, etc. These are
-distinct types; even if <code>int</code> and <code>int32</code> are both 32 bits in size,
+unsigned integer types such as <code>uint</code>, <code>uint32</code>, etc.
+These are distinct types; even if <code>int</code> and <code>int32</code> are both 32 bits in size,
they are not the same type. There is also a <code>byte</code> synonym for
<code>uint8</code>, which is the element type for strings.
<p>
+Floating-point types are always sized: <code>float32</code> and <code>float64</code>,
+plus <code>complex64</code> (two <code>float32s</code>) and <code>complex128</code>
+(two <code>float64s</code>). Complex numbers are outside the
+scope of this tutorial.
+<p>
Speaking of <code>string</code>, that's a built-in type as well. Strings are
<i>immutable values</i>&mdash;they are not just arrays of <code>byte</code> values.
Once you've built a string <i>value</i>, 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
</pre>
<p>
Conversions only work for simple cases such as converting <code>ints</code> of one
-sign or size to another, and between <code>ints</code> and <code>floats</code>, 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.
<p>
@@ -538,9 +544,9 @@ We can use the factory to construct some familiar, exported variables of type <c
<p>
<pre> <!-- progs/file.go /var/ /^.$/ -->
24 var (
-25 Stdin = newFile(0, &quot;/dev/stdin&quot;)
-26 Stdout = newFile(1, &quot;/dev/stdout&quot;)
-27 Stderr = newFile(2, &quot;/dev/stderr&quot;)
+25 Stdin = newFile(syscall.Stdin, &quot;/dev/stdin&quot;)
+26 Stdout = newFile(syscall.Stdout, &quot;/dev/stdout&quot;)
+27 Stderr = newFile(syscall.Stderr, &quot;/dev/stderr&quot;)
28 )
</pre>
<p>
@@ -663,7 +669,7 @@ something from the directory of installed packages.
(Also, ''<code>file.go</code>'' must be compiled before we can import the
package.)
<p>
-Now we can compile and run the program:
+Now we can compile and run the program. On Unix, this would be the result:
<p>
<pre>
$ 6g file.go # compile file package