diff options
Diffstat (limited to 'doc/go_tutorial.html')
-rw-r--r-- | doc/go_tutorial.html | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/doc/go_tutorial.html b/doc/go_tutorial.html index 27710ed26..cdf1443e9 100644 --- a/doc/go_tutorial.html +++ b/doc/go_tutorial.html @@ -147,7 +147,7 @@ or we could go even shorter and write the idiom </pre> <p> The <code>:=</code> operator is used a lot in Go to represent an initializing declaration. -(For those who know Sawzall, its <code>:=</code> construct is the same, but notice +(For those who know Limbo, its <code>:=</code> construct is the same, but notice that Go has no colon after the name in a full <code>var</code> declaration. Also, for simplicity of parsing, <code>:=</code> only works inside functions, not at the top level.) @@ -878,9 +878,9 @@ argument. It's easier in many cases in Go. Instead of <code>%llud</code> you can just say <code>%d</code>; <code>Printf</code> knows the size and signedness of the integer and can do the right thing for you. The snippet <p> -<pre> <!-- progs/print.go NR==6 NR==7 --> -06 -07 import "fmt" +<pre> <!-- progs/print.go NR==10 NR==11 --> +10 var u64 uint64 = 1<<64-1; +11 fmt.Printf("%d %d\n", u64, int64(u64)); </pre> <p> prints @@ -892,11 +892,11 @@ prints In fact, if you're lazy the format <code>%v</code> will print, in a simple appropriate style, any value, even an array or structure. The output of <p> -<pre> <!-- progs/print.go NR==10 NR==13 --> -10 var u64 uint64 = 1<<64-1; -11 fmt.Printf("%d %d\n", u64, int64(u64)); -<p> -13 // harder stuff +<pre> <!-- progs/print.go NR==14 NR==17 --> +14 type T struct { a int; b string }; +15 t := T{77, "Sunset Strip"}; +16 a := []int{1, 2, 3, 4}; +17 fmt.Printf("%v %v %v\n", u64, t, a); </pre> <p> is @@ -912,9 +912,9 @@ of <code>%v</code> while <code>Println</code> automatically inserts spaces betwe and adds a newline. The output of each of these two lines is identical to that of the <code>Printf</code> call above. <p> -<pre> <!-- progs/print.go NR==14 NR==15 --> -14 type T struct { a int; b string }; -15 t := T{77, "Sunset Strip"}; +<pre> <!-- progs/print.go NR==18 NR==19 --> +18 fmt.Print(u64, " ", t, " ", a, "\n"); +19 fmt.Println(u64, t, a); </pre> <p> If you have your own type you'd like <code>Printf</code> or <code>Print</code> to format, @@ -923,11 +923,7 @@ routines will examine the value to inquire whether it implements the method and if so, use it rather than some other formatting. Here's a simple example. <p> -<pre> <!-- progs/print_string.go NR==5 END --> -05 package main -<p> -07 import "fmt" -<p> +<pre> <!-- progs/print_string.go NR==9 END --> 09 type testType struct { a int; b string } <p> 11 func (t *testType) String() string { |