working on re-arranging

This commit is contained in:
Mark McGranaghan 2012-09-23 12:11:48 -04:00
parent dfd2c39463
commit 785a0d123b
114 changed files with 167 additions and 139 deletions

View File

@ -1,12 +0,0 @@
package main // Here's an example Go program.
import "fmt"
func main() {
fmt.Println("Hello world") // It prints `Hello world`.
}
/*
$ go run hello-world.go // Put this code in hello-world.go,
Hello world // then use `go run` to run it.
*/

View File

@ -0,0 +1,11 @@
// ## Hello World
// Here's an example Go program.
package main
import "fmt"
// It prints `Hello world`.
func main() {
fmt.Println("Hello world")
}

View File

@ -0,0 +1,2 @@
$ go run hello-world.go
Hello world

View File

@ -1,26 +0,0 @@
package main // Go has various value types, including strings,
// different types of numbers, booleans, etc.
import "fmt"
func main() {
fmt.Println("Hello world") // Strings.
fmt.Println("Hello " + "other")
fmt.Println("1+1 =", 1+1) // Integers and floats.
fmt.Println("7.0/3.0 =", 7.0/3.0)
fmt.Println(true && false) // Booleans.
fmt.Println(true || false)
fmt.Println(!true)
}
/*
$ go run values.go
Hello world
Hello other
1+1 = 2
7.0/3.0 = 2.3333333333333335
false
true
false
*/

23
002-values/values.go Normal file
View File

@ -0,0 +1,23 @@
// ## Values
// Go has various value types, including strings,
// different types of numbers, booleans, etc.
package main
import "fmt"
func main() {
// Here are some strings, which can be added together.
fmt.Println("Hello world")
fmt.Println("Hello " + "other")
// Some examples of integers and floats.
fmt.Println("1+1 =", 1+1)
fmt.Println("7.0/3.0 =", 7.0/3.0)
// And booleans, which work as you'd expect.
fmt.Println(true && false)
fmt.Println(true || false)
fmt.Println(!true)
}

8
002-values/values.sh Normal file
View File

@ -0,0 +1,8 @@
$ go run values.go
Hello world
Hello other
1+1 = 2
7.0/3.0 = 2.3333333333333335
false
true
false

View File

@ -1,17 +0,0 @@
package main
import "fmt"
func main() {
var x string = "Hello world" // `var` declares 1 or more variables. The type comes
fmt.Println(x) // at the end.
var a, b int = 1, 2 // An example of declaring multiple `int` variables.
fmt.Println(a, b)
}
/*
$ go run variables.go
Hello world
1 2
*/

View File

@ -0,0 +1,16 @@
// ## Variables
package main
import "fmt"
func main() {
// `var` declares 1 or more variables. The type comes
// at the end.
var x string = "Hello world"
fmt.Println(x)
// An example of declaring multiple `int` variables.
var a, b int = 1, 2
fmt.Println(a, b)
}

View File

@ -0,0 +1 @@
go run variables.go

View File

@ -1,17 +0,0 @@
package main
import "fmt"
func main() {
var x string
x = "first"
fmt.Println(x)
x = "second" // You can mutate variables in Go.
fmt.Println(x)
}
/*
$ go run mutation.go
first
second
*/

16
004-mutation/mutation.go Normal file
View File

@ -0,0 +1,16 @@
// ## Mutation
package main
import "fmt"
func main() {
var x string
x = "old"
fmt.Println(x)
// You can mutate variables in Go by re-assigning the
// variable to a new value.
x = "new"
fmt.Println(x)
}

3
004-mutation/mutation.sh Normal file
View File

@ -0,0 +1,3 @@
$ go run mutation.go
old
new

View File

@ -1,16 +0,0 @@
package main
import "fmt"
func main() {
x := "Hello literal" // `x := val` is shorthand for `var x type = val`.
fmt.Println(x)
}
/*
$ go run literal.go
Hello literal
*/
// == todo
// literal?

14
005-literals/literals.go Normal file
View File

@ -0,0 +1,14 @@
// ## Literals
package main
import "fmt"
func main() {
// `x := val` is shorthand for `var x type = val`.
x := "Hello literal"
fmt.Println(x)
}
// todo: literal term?

2
005-literals/literals.sh Normal file
View File

@ -0,0 +1,2 @@
$ go run literal.go
Hello literal

View File

@ -1,9 +0,0 @@
package main
import "fmt"
const x string = "Hello World"
func main() {
fmt.Println(x)
}

View File

@ -0,0 +1,15 @@
// ## Constants
package main
import "fmt"
// Use `const` to declare a constant value.
// Constants can be ...
const x string = "Hello World"
func main() {
fmt.Println(x)
}
// todo: research

View File

@ -0,0 +1,2 @@
$ go run constant.go
Hello World

View File

@ -1,3 +1,5 @@
// ## Reading Input
package main
import "fmt"

View File

@ -0,0 +1,3 @@
$ go run reading-input.go
Enter a number: 7
7 * 2 = 14

View File

@ -1,28 +0,0 @@
package main // `for` is Go's only looping construct. Below are
// two common forms.
import "fmt"
func main() {
i := 1 // Initialize `i` with `1` and loop until it's 10.
for i <= 3 {
fmt.Print(i)
i = i + 1
}
for j := 1; j <= 3; j++ { // That type of loop is common. We can do it on one
fmt.Print(j) // line.
}
for { // `for` without a condition will loop until you
fmt.Println() // `return`.
return
}
} // We'll see other `for` forms latter.
/*
$ go run for.go
123123
*/
// == todo
// break out of for loop?

34
008-for/for.go Normal file
View File

@ -0,0 +1,34 @@
// ## For
// `for` is Go's only looping construct. Here are
// two common forms.
package main
import "fmt"
func main() {
// Initialize `i` with `1` and loop until it's 10.
i := 1
for i <= 3 {
fmt.Print(i)
i = i + 1
}
// That type of loop is common. We can do it on one
// line.
for j := 1; j <= 3; j++ {
fmt.Print(j)
}
// `for` without a condition will loop until you
// `return`.
for {
fmt.Println()
return
}
}
// We'll see other `for` forms latter.
// todo: break out of for loop?

2
008-for/for.sh Normal file
View File

@ -0,0 +1,2 @@
$ go run for.go
123123

View File

@ -34,5 +34,4 @@ func main() {
fmt.Println(rectangle.area())
}
// == todo
// pointer vs value receivers
// todo: pointer vs value receivers

View File

@ -50,6 +50,5 @@ func main() {
fmt.Println(area)
}
// == todo
// is this named wrong?
// note about embedding access
// todo: is this named wrong?
// todo: note about embedding access

View File

@ -1,6 +1,7 @@
package main
import ("time"; "fmt")
import "time"
import "fmt"
func main() {
tick := time.Tick(time.Millisecond * 200)
@ -21,5 +22,4 @@ func main() {
}
}
// == todo
// credit http://code.google.com/p/go-wiki/wiki/RateLimiting
// todo: credit http://code.google.com/p/go-wiki/wiki/RateLimiting

Some files were not shown because too many files have changed in this diff Show More