2008-11-13 18:50:46 -07:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
2008-12-02 17:49:44 -07:00
|
|
|
import (
|
|
|
|
"array"; // not needed
|
|
|
|
"utf8"; // not needed
|
|
|
|
Fmt "fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2008-12-11 18:45:45 -07:00
|
|
|
const /* enum1 */ (
|
2008-12-02 17:49:44 -07:00
|
|
|
EnumTag0 = iota;
|
|
|
|
EnumTag1;
|
|
|
|
EnumTag2;
|
|
|
|
EnumTag3;
|
|
|
|
EnumTag4;
|
|
|
|
EnumTag5;
|
|
|
|
EnumTag6;
|
|
|
|
EnumTag7;
|
|
|
|
EnumTag8;
|
|
|
|
EnumTag9;
|
|
|
|
)
|
2008-11-13 18:50:46 -07:00
|
|
|
|
|
|
|
|
2008-12-11 18:45:45 -07:00
|
|
|
const /* enum2 */ (
|
|
|
|
a, b = iota*2 + 1, iota*2;
|
|
|
|
c, d;
|
|
|
|
e, f;
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2008-12-02 18:01:31 -07:00
|
|
|
type S struct {}
|
|
|
|
|
|
|
|
|
2008-11-13 18:50:46 -07:00
|
|
|
type T struct {
|
|
|
|
x, y int;
|
|
|
|
s string;
|
|
|
|
next_t *T
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
A = 5;
|
2008-12-11 18:45:45 -07:00
|
|
|
u, v, w int = 0, 0, 0;
|
2008-11-13 18:50:46 -07:00
|
|
|
foo = "foo";
|
2009-01-06 18:39:25 -07:00
|
|
|
fixed_array0 = [10]int{};
|
|
|
|
fixed_array1 = [10]int{0, 1, 2};
|
|
|
|
fixed_array2 = [...]string{"foo", "bar"};
|
2008-11-13 18:50:46 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2009-01-08 13:04:00 -07:00
|
|
|
func d0() {
|
|
|
|
var (
|
|
|
|
a string;
|
|
|
|
b, c string;
|
|
|
|
d, e, f string;
|
|
|
|
g, h, i, j string;
|
|
|
|
k, l, m, n, o string;
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-26 18:07:45 -07:00
|
|
|
func f0(a, b int) int {
|
|
|
|
if a < b {
|
|
|
|
a = a + 1; // estimate
|
|
|
|
}
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-02 17:49:44 -07:00
|
|
|
func f1(tag int) {
|
|
|
|
switch tag {
|
|
|
|
case
|
|
|
|
EnumTag0, EnumTag1, EnumTag2, EnumTag3, EnumTag4,
|
|
|
|
EnumTag5, EnumTag6, EnumTag7, EnumTag8, EnumTag9: break;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-03 16:47:30 -07:00
|
|
|
func f2(tag int) {
|
2008-12-04 19:18:41 -07:00
|
|
|
type T struct {}
|
2008-12-03 16:47:30 -07:00
|
|
|
var x T
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-19 04:05:37 -07:00
|
|
|
func f3(a *[]int, m map[string] int) {
|
2008-12-11 18:45:45 -07:00
|
|
|
println("A1");
|
|
|
|
for i := range a {
|
|
|
|
println(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
println("A2");
|
|
|
|
for i, x := range a {
|
|
|
|
println(i, x);
|
|
|
|
}
|
|
|
|
|
|
|
|
println("A3");
|
|
|
|
for i : x := range a {
|
|
|
|
println(i, x);
|
|
|
|
}
|
|
|
|
|
|
|
|
println("M1");
|
|
|
|
for i range m {
|
|
|
|
println(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
println("M2");
|
|
|
|
for i, x range m {
|
|
|
|
println(i, x);
|
|
|
|
}
|
|
|
|
|
|
|
|
println("M3");
|
|
|
|
var i string;
|
|
|
|
var x int;
|
|
|
|
for i : x = range m {
|
|
|
|
println(i, x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-13 18:50:46 -07:00
|
|
|
func main() {
|
2008-11-17 20:58:52 -07:00
|
|
|
// the prologue
|
2008-11-13 18:50:46 -07:00
|
|
|
for i := 0; i <= 10 /* limit */; i++ {
|
|
|
|
println(i); // the index
|
|
|
|
println(i + 1); // the index + 1
|
|
|
|
println(i + 1000); // the index + 1000
|
|
|
|
println();
|
|
|
|
}
|
2008-12-11 18:45:45 -07:00
|
|
|
f3(&[]int{2, 3, 5, 7}, map[string]int{"two":2, "three":3, "five":5, "seven":7});
|
2008-11-17 20:58:52 -07:00
|
|
|
// the epilogue
|
2008-11-13 18:50:46 -07:00
|
|
|
println("foo"); // foo
|
|
|
|
println("foobar"); // foobar
|
2008-11-26 18:07:45 -07:00
|
|
|
var x int; // declare x
|
2008-11-13 18:50:46 -07:00
|
|
|
}
|