Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 177 lines (152 sloc) 6.901 kb
7811b5c @miekg Fix all the quotes and more [from: Stefan Schroeder]
authored
1 \epi{``I am interested in this and hope to do something.''}
1f704ac @miekg sorta fix small caps
authored
2 {\textit{On adding complex numbers to Go}\\ \textsc{KEN THOMPSON}}
30324e7 @miekg added google logo
authored
3
f4a1ee3 @miekg add a small preface
authored
4 \noindent{}What is Go? From the website \cite{go_web}:
7ae1471 @miekg final phase for 0.2
authored
5 \begin{quote}
6 The Go programming language is an open source project to make
7 programmers more productive. Go is expressive, concise, clean, and
8 efficient. Its concurrency mechanisms make it easy to write programs
5c25b47 @miekg Spell check
authored
9 that get the most out of multi core and networked machines, while its
7ae1471 @miekg final phase for 0.2
authored
10 novel type system enables flexible and modular program construction. Go
11 compiles quickly to machine code yet has the convenience of garbage
12 collection and the power of run-time reflection. It's a fast, statically
13 typed, compiled language that feels like a dynamically typed,
14 interpreted language.
15 \end{quote}
3dd4e3f @miekg change the introduction a bit (order)
authored
16
f1d9418 @miekg Fix the intro and stuff for Go 1
authored
17 Go 1 is the first stable release of the language Go.
f37b9eb @miekg easier difficulty settings for exercises
authored
18 This document and all exercises work with Go 1 -- if not, it's a bug.
7ae1471 @miekg final phase for 0.2
authored
19
20 The following convention is used throughout this book:
164f7a7 @miekg start new repo
authored
21 \begin{itemize}
c5c6e34 @miekg Correct font in graphics (dejavu)
authored
22 \item Code is displayed in \prog{DejaVu Mono};
23 \item Keywords are displayed in \key{DejaVu Mono Bold};
24 \item Comments are displayed in \rem{DejaVu Mono Italic};
aa4f15b @miekg add more stuff about defer
authored
25 \item Extra remarks in the code \coderemark{Are displayed like this};
24a8471 @miekg small style changes
authored
26 \item Longer remarks get a number -- \gocircle{1} -- with the explanation following;
57068d9 @miekg style fixes
authored
27 \item Line numbers are printed on the right side;
c80be2c @miekg Use letters for footnotes
authored
28 \item Shell examples use a \pr{} as prompt;
bc1bf00 @miekg some minor changes
authored
29 \item User entered text in shell examples \texttt{\user{is in bold}}, system responses
30 are in a \texttt{typewriter font};
278d4d4 @miekg spell check
authored
31 \item An emphasized paragraph is indented and has a vertical bar on the
c80be2c @miekg Use letters for footnotes
authored
32 left.
164f7a7 @miekg start new repo
authored
33 \end{itemize}
34
35 \section{Official documentation}
fb87c1c @miekg JCs comments for chapter 1
authored
36 There already is a substantial amount of documentation written about Go.
7811b5c @miekg Fix all the quotes and more [from: Stefan Schroeder]
authored
37 \gomarginpar{When searching on the internet use the term ``golang'' instead of plain ``go''.}
fb87c1c @miekg JCs comments for chapter 1
authored
38 The Go Tutorial \cite{go_tutorial}, and the Effective Go
164f7a7 @miekg start new repo
authored
39 document \cite{effective_go}. The
fb87c1c @miekg JCs comments for chapter 1
authored
40 website \url{http://golang.org/doc/} is a very good starting point
8966fda @miekg more proof reading fixes
authored
41 for reading up on Go\footnote{\url{http://golang.org/doc/} itself is served by
35e2e93 @miekg Fix godoc and go\ doc as per Rob Pike s suggestion
authored
42 \prog{go doc}.}. Reading these documents is
f1d9418 @miekg Fix the intro and stuff for Go 1
authored
43 certainly not required, but it is recommended.
44
35e2e93 @miekg Fix godoc and go\ doc as per Rob Pike s suggestion
authored
45 Go 1 comes with its own documentation in the form of a program called
41f32ed @miekg fix typo (Philipp)
authored
46 \prog{go doc}. If you are interested in the documentation
35e2e93 @miekg Fix godoc and go\ doc as per Rob Pike s suggestion
authored
47 for the built-ins (see ``\titleref{sec:builtins}'' in the next chapter) you
48 can fire it up, like so:
f1d9418 @miekg Fix the intro and stuff for Go 1
authored
49 \begin{display}
35e2e93 @miekg Fix godoc and go\ doc as per Rob Pike s suggestion
authored
50 \pr \user{go doc builtin}
f1d9418 @miekg Fix the intro and stuff for Go 1
authored
51 \end{display}
52
53 How to create your own package documentation is explained in chapter \ref{chap:packages}.
7ae1471 @miekg final phase for 0.2
authored
54
3ab1e13 @miekg Update the intro chapter
authored
55 \section{Origins}
56 Go has it origins in Inferno \cite{inferno} (which in turn was based
57 upon Plan 9 \cite{plan9}). Inferno included a language called Limbo
58 \cite{limbo}. Quoting from the Limbo paper:
59 \begin{quote}
60 Limbo is a programming language intended for applications running
61 distributed systems on small computers. It supports modular programming,
62 strong type checking at compile- and run-time, \emph{inter process
63 communication over typed channels}, automatic \emph{garbage collection}, and
64 simple abstract data types. It is designed for safe execution even on
65 small machines without hardware memory protection.
66 \end{quote}
67 A feature Go inherited from Limbo is channels (see chapter
68 \ref{chap:channels}). Again from the Limbo documentation.
69 \begin{quote}
70 [A channel] is a communication mechanism capable of sending and receiving objects of
71 the specified type to another agent in the system. Channels may be used
72 to communicate between local processes; using library procedures, they
73 may be connected to named destinations. In either case send and receive
74 operations may be directed to them.
75 \end{quote}
76 The channels in Go are easier to use than those in Limbo.
77 If we dig even deeper in the history of Go we also find references
7811b5c @miekg Fix all the quotes and more [from: Stefan Schroeder]
authored
78 to ``Newsqueak'' \cite{newsqueak}, which pioneered the use of
3ab1e13 @miekg Update the intro chapter
authored
79 channel communication in a C--like language. Channel
80 communication isn't unique to these languages, a big non--C--like
81 language which also uses them is Erlang \cite{erlang}.
82
83 \begin{figure}[H]
84 \caption{Chronology of Go}
85 \label{fig:chrono-of-go}
86 \begin{center}
87 \includegraphics[scale=0.65]{fig/go-history.pdf}
88 \end{center}
89 \end{figure}
90
91 The whole of idea of using channels to communicate with other processes
92 is called Communicating Sequential Processes (CSP) and was conceived
93 by C. A. R. Hoare \cite{hoare}, who incidentally is the same man that
94 invented QuickSort \cite{quicksort}.
95
96 \begin{lbar}[]
97 Go is the first C--like language that is widely available,
98 runs on many
99 different platforms and makes concurrency easy (or easier).
100 \end{lbar}
101
0f58f2a @miekg First set of improvements
authored
102 \section{Getting Go}
3ab1e13 @miekg Update the intro chapter
authored
103 In this section we tell how to install Go locally on your machine, but you can
104 also compile Go code online at \url{http://play.golang.org/}. To quickly
105 play with code this is by far the easiest route.
106
f1d9418 @miekg Fix the intro and stuff for Go 1
authored
107 You can also get pre-compiled binaries from \cite{go_install}.
108
cb09cad @miekg add a note about packages that exist
authored
109 Ubuntu and Debian both have a Go package in their repositories, look for
7811b5c @miekg Fix all the quotes and more [from: Stefan Schroeder]
authored
110 the package ``golang''. But there are still some minor issues being worked
cb09cad @miekg add a note about packages that exist
authored
111 out. For now we will stick to the installation from source.
112
f1d9418 @miekg Fix the intro and stuff for Go 1
authored
113 So we will have to retrieve the code from the mercurial archive and compile
114 Go yourself. For other Unix-like systems the procedure is the same.
164f7a7 @miekg start new repo
authored
115 \begin{itemize}
fb87c1c @miekg JCs comments for chapter 1
authored
116 \item First install Mercurial (to get the \prog{hg} command). In
164f7a7 @miekg start new repo
authored
117 Ubuntu/Debian/Fedora you must install the \prog{mercurial} package;
118
1e848fe @miekg more tweaks to the first 2 chapters
authored
119 \item For building Go you need the packages: \prog{bison},
164f7a7 @miekg start new repo
authored
120 \prog{gcc}, \prog{libc6-dev}, \prog{ed}, \prog{gawk} and \prog{make};
121
9d694e4 @miekg more fixes for the intro chapter
authored
122 \item Set the environment variable \prog{GOROOT} to the root of your
123 Go install:
124 \begin{display}
f1d9418 @miekg Fix the intro and stuff for Go 1
authored
125 \pr \user{export GOROOT=\~{}/go}
9d694e4 @miekg more fixes for the intro chapter
authored
126 \end{display}
127
f1d9418 @miekg Fix the intro and stuff for Go 1
authored
128 \item Then retrieve the latest release (= Go 1) source code:
e454eba @miekg better spacing
authored
129 \begin{display}
091ca7a @miekg Some shell examples updates
authored
130 \pr \user{hg clone -r release https://go.googlecode.com/hg/ $GOROOT}
e454eba @miekg better spacing
authored
131 \end{display}
b26ce31 @miekg clear up the first chapter
authored
132
d7e8809 @miekg Multiple updates
authored
133 \item Set your PATH to so that the shell can find the Go binaries:
b26ce31 @miekg clear up the first chapter
authored
134 \begin{display}
091ca7a @miekg Some shell examples updates
authored
135 \pr \user{export PATH=$GOROOT/bin:$PATH}
b26ce31 @miekg clear up the first chapter
authored
136 \end{display}
164f7a7 @miekg start new repo
authored
137 \item Compile Go
e454eba @miekg better spacing
authored
138 \begin{display}
091ca7a @miekg Some shell examples updates
authored
139 \pr \user{cd $GOROOT/src}
140 \pr \user{./all.bash}
e454eba @miekg better spacing
authored
141 \end{display}
164f7a7 @miekg start new repo
authored
142 \end{itemize}
b4d7f06 @miekg Fix use of \user in display's
authored
143 If all goes well, you should see the following at the end:
9d694e4 @miekg more fixes for the intro chapter
authored
144 \begin{display}
b4d7f06 @miekg Fix use of \user in display's
authored
145 --- cd ../test
146 0 known bugs; 0 unexpected bugs
147
148 ALL TESTS PASSED
149
150 ---
151 Installed Go for linux/amd64 in /home/go
152 Installed commands in /home/go/bin
9d694e4 @miekg more fixes for the intro chapter
authored
153 \end{display}
154
c8f8b29 @miekg add the Windows text from Paulo Pinto
authored
155 \section{Getting Go for Windows}
c239457 @miekg Fix chap 1 for Go-1
authored
156 The best way is to follow the instructions from \cite{go_install}, which are repeated
157 here for your convience.
c8f8b29 @miekg add the Windows text from Paulo Pinto
authored
158
159 \begin{itemize}
35e2e93 @miekg Fix godoc and go\ doc as per Rob Pike s suggestion
authored
160 \item Download Go 1 from:
f1d9418 @miekg Fix the intro and stuff for Go 1
authored
161 \url{http://code.google.com/p/go/downloads/list?q=OpSys-Windows+Type%3DArchive};
162 \item Unpack it to your \verb|C:\| drive;
163 \item Make sure that the contents are \verb|C:\Go|. Note: this directory should be
164 created when you unpacked the zip;
165 \item Add \verb|C:\Go\bin| to your \$PATH:
c8f8b29 @miekg add the Windows text from Paulo Pinto
authored
166 \begin{display}
6e35f37 Updated Windows command to add correct way to add go to the systems P…
Robert Johnson authored
167 set PATH=\verb|%PATH%;C:\Go\bin|
c8f8b29 @miekg add the Windows text from Paulo Pinto
authored
168 \end{display}
169 \end{itemize}
170
164f7a7 @miekg start new repo
authored
171 \section{Exercises}
16a6b17 @miekg add another question
authored
172 \input{ex-intro/ex-doc.tex}
173
164f7a7 @miekg start new repo
authored
174 \cleardoublepage
175 \section{Answers}
176 \shipoutAnswer
Something went wrong with that request. Please try again.