Permalink
Browse files

A few typos and adjusted wording slightly to sound better.

  • Loading branch information...
wayneeseguin committed Dec 29, 2011
1 parent 74c6b62 commit 1d408485bc54601023d5224739506f19eb94ebde
Showing with 79 additions and 79 deletions.
  1. +20 −20 basic.rst
  2. +30 −30 control.rst
  3. +21 −21 functions.rst
  4. +8 −8 hello.rst
View
@@ -2,17 +2,17 @@
The basic things
****************
-In the previous chapter, we saw that Go programs are organized in *packages* and
-that Go natively supports UTF-8 for strings and identifiers. In this chapter we
-will see how to declare and use variables and constants and the different Go
+In the previous chapter, we saw that Go programs are organized using *packages*
+and that Go natively supports UTF-8 for strings and identifiers. In this chapter
+we will see how to declare and use variables and constants and the different Go
built-in types.
How to declare a variable?
==========================
-There are several ways to declare a variable in Go.
+There are several ways to declare a variable in Go.
-The basic form is:
+The basic form is:
.. code-block:: go
@@ -47,8 +47,8 @@ Guess what? You can omit the type and it will be inferred from the initializers
.. code-block:: go
- /* declare and initialize var1, var2 and var3 and initialize them to
- respectively: value1, value2, and value3 /
+ /* declare and initialize var1, var2 and var3 and initialize them
+ respectively to value1, value2, and value3. /
var var1, var2, var3 = value1, value2, value3
Even shorter, inside a function body (let me repeat that: only inside a function
@@ -78,24 +78,24 @@ one of the values: ``true`` or ``false``.
.. code-block:: go
:linenos:
-
+
//Example snippet
var active bool //basic form
var enabled, disabled = true, false //type omitted, variables initialized
func test(){
var available bool //general form
valid := false //type and var omitted, and variable initialized
- available = true //normal assignation
+ available = true //normal assignation
}
-
+
Numeric types
-------------
For integer values, signed and unsigned, Go has ``int`` and ``uint`` both having
the appropriate length for your machine (32 or 64 bits) But there's also
explicit sized ints: ``int8``, ``int16``, ``int32``, ``int64`` and ``byte``,
``uint8``, ``uint16``, ``uint32``, ``uint64``. With ``byte`` being an alias for
-``uint8``.
+``uint8``.
For floating point values, we have ``float32`` and ``float64``.
@@ -120,7 +120,7 @@ From the `Go Programming Language Specification`_
+----------+----------------------------------------------------------------------------------------+
|uint64 | the set of all unsigned 64-bit integers (0 to 18446744073709551615) |
+----------+----------------------------------------------------------------------------------------+
-| |
+| |
+----------+----------------------------------------------------------------------------------------+
|int8 | the set of all signed 8-bit integers (-128 to 127) |
+----------+----------------------------------------------------------------------------------------+
@@ -130,35 +130,35 @@ From the `Go Programming Language Specification`_
+----------+----------------------------------------------------------------------------------------+
|int64 | the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807) |
+----------+----------------------------------------------------------------------------------------+
-| |
+| |
+----------+----------------------------------------------------------------------------------------+
|float32 | the set of all IEEE-754 32-bit floating-point numbers |
+----------+----------------------------------------------------------------------------------------+
|float64 | the set of all IEEE-754 64-bit floating-point numbers |
+----------+----------------------------------------------------------------------------------------+
-| |
+| |
+----------+----------------------------------------------------------------------------------------+
|complex64 | the set of all complex numbers with float32 real and imaginary parts |
+----------+----------------------------------------------------------------------------------------+
|complex128| the set of all complex numbers with float64 real and imaginary parts |
+----------+----------------------------------------------------------------------------------------+
-| |
+| |
+----------+----------------------------------------------------------------------------------------+
| byte familiar alias for uint8 |
+----------+----------------------------------------------------------------------------------------+
.. code-block:: go
:linenos:
-
+
//Example snippet
var i int32 //basic form with a int32
var x, y, z = 1, 2, 3 //type omitted, variables initialized
func test(){
var pi float32 //basic form
one, two, thre := 1, 2, 3 //type and var omitted, variables initialized
c := 10+3i // a complex number, type infered and keyword 'var' omitted.
- pi = 3.14 // normal assignation
+ pi = 3.14 // normal assignation
}
Strings
@@ -168,14 +168,14 @@ between two double quotes (") and their type is -you bet!- ``string``.
.. code-block:: go
:linenos:
-
+
//Example snippet
var french_hello string //basic form
var empty_string string = "" // here empty_string (like french_hello) equals ""
func test(){
no, yes, maybe := "no", "yes", "maybe" //var and type omitted
japanese_hello := "Ohaiou" //type inferred, var keyword omitted
- french_hello = "Bonjour" //normal assignation
+ french_hello = "Bonjour" //normal assignation
}
Constants
@@ -186,7 +186,7 @@ can be: numbers, boolean or strings.
The syntax to declare a constant is:
.. code-block:: go
-
+
const constant_name = value
Some examples:
View
@@ -10,7 +10,7 @@ data. But before that, let's talk about comments and semicolons.
Comments
========
You probably noticed in the example snippets given in previous chapters, some
-comments. Didn't you?
+comments. Didn't you?
Go, have the same comments convention as in C++. That is:
* Single line comments: Everything from ``//`` until the end of the line is a
@@ -21,7 +21,7 @@ Go, have the same comments convention as in C++. That is:
:linenos:
//Single line comment, this is ignored by the compiler.
- /* Everything from now on until the keyword var on line 4
+ /* Everything from now on until the keyword var on line 4
is a comment, and is ignored by the compiler*/
var(
i int
@@ -39,9 +39,9 @@ line end that looks like the end of a statement.
And this makes the code a lot cleaner, and easy on the eyes.
the only place you typically see semicolons is separating the clauses of for
-loops and the like; they are not necessary after every statement.
+loops and the like; they are not necessary after every statement.
-Note that you can use semicolons to separate sevral statements written on the
+Note that you can use semicolons to separate several statements written on the
same line.
The one surprise is that it's important to put the opening brace of a construct
@@ -61,9 +61,9 @@ In Go, you don't need parenthesis for the condition.
:linenos:
if x>10{
- fmt.Println("x is greater than 10")
+ fmt.Println("x is greater than 10")
} else {
- fmt.Println("x is less than 10")
+ fmt.Println("x is less than 10")
}
You can also have a leading initial short statement before the condition too.
@@ -73,9 +73,9 @@ You can also have a leading initial short statement before the condition too.
// compute the value of x, and then compare.
if x := computed_value(); x>10{
- fmt.Println("x is greater than 10")
+ fmt.Println("x is greater than 10")
} else {
- fmt.Println("x is less than 10")
+ fmt.Println("x is less than 10")
}
You can combine multiple if/else statements.
@@ -84,11 +84,11 @@ You can combine multiple if/else statements.
:linenos:
if i == 3 {
- fmt.Println("i is equal to 3")
+ fmt.Println("i is equal to 3")
} else if i < 3{
- fmt.Println("i is less than 3")
+ fmt.Println("i is less than 3")
} else {
- fmt.Println("i is greater than 3")
+ fmt.Println("i is greater than 3")
}
The for statement
@@ -100,7 +100,7 @@ Its general syntax is:
:linenos:
for expression1; expression2; expression3{
- ...
+ ...
}
Gramatically, ``expression1``, ``expression2``, and ``expression3`` are
@@ -126,7 +126,7 @@ An example would be better than the previous paragraph, right? Here we go!
}
we initalize our variable ``sum`` to 0; and we start our ``for`` loop with
-initializing the variable ``i`` to 0; (``i:=0``) and we execute the for loop's
+initializing the variable ``i`` to 0; (``i:=0``) and we execute the for loop's
body (``sum += i``) *while* the condition ``i<10`` is met, and at the end of
each iteration, we execute the ``i++`` expression (increment i)
@@ -190,7 +190,7 @@ condition expressed by ``expression2`` is still true.
for i:=10; i>0; i--{
if i<5{
- break
+ break
}
fmt.Println("i")
}
@@ -231,11 +231,11 @@ The general form of a switch statement is
//general form of a switch statement
switch sExpr {
- case expr1:
+ case expr1:
some instructions
- case expr2:
+ case expr2:
some other instructions
- case expr3:
+ case expr3:
some other instructions
default:
other code
@@ -273,19 +273,19 @@ Some switch examples:
//simple switch example
i := 10
switch i {
- case 1:
+ case 1:
fmt.Println("i is equal to 1")
- case 2, 3, 4:
+ case 2, 3, 4:
fmt.Println("i is equal to 2, 3 or 4")
- case 10:
+ case 10:
fmt.Println("i is equal to 10")
default:
fmt.Println("All I know is that i is an integer")
}
In this snippet, we initialized ``i`` to 10, but in practice, you should think
of ``i`` as a computed value (result of a function or some other calculus before
-the switch statement)
+the switch statement)
Notice that in line 6, we grouped some expressions (2, 3, and 4) in a single
case statement.
@@ -296,11 +296,11 @@ case statement.
//switch example without sExpr
i := 10
switch {
- case i<10:
+ case i<10:
fmt.Println("i is less than 10")
- case i>10, i<0:
+ case i>10, i<0:
fmt.Println("i is either bigger than 10 or less than 0")
- case i==10:
+ case i==10:
fmt.Println("i is equal to 10")
default:
fmt.Println("This won't be printed anyway")
@@ -320,23 +320,23 @@ reached?
//switch example with fallthrough
i := 6
switch i {
- case 4:
+ case 4:
fmt.Println("was <= 4")
fallthrough
- case 5:
+ case 5:
fmt.Println("was <= 5")
fallthrough
case 6:
fmt.Println("was <= 6")
fallthrough
- case 7:
+ case 7:
fmt.Println("was <= 7")
fallthrough
- case 8:
+ case 8:
fmt.Println("was <= 8")
fallthrough
- default:
- fmt.Println("default case")
+ default:
+ fmt.Println("default case")
}
In this example, the case on line 10 matches, but since there is
Oops, something went wrong.

0 comments on commit 1d40848

Please sign in to comment.