Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

Commit

Permalink
more on variadac args
Browse files Browse the repository at this point in the history
remove \noindents
  • Loading branch information
miekg committed Jul 25, 2010
1 parent 6b310c9 commit f800954
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
6 changes: 3 additions & 3 deletions go-appendix.tex
Expand Up @@ -19,7 +19,7 @@ \section{Expression versus statement}
\begin{display}
1 + 2 / X
\end{display}
\noindent{}is an error in FORTRAN, because it doesn't do anything. You had to do
is an error in FORTRAN, because it doesn't do anything. You had to do
something with that expression:
\begin{display}{X = 1 + 2 / X}\end{display}

Expand All @@ -30,11 +30,11 @@ \section{Expression versus statement}
expression and throw away the result. In C, every expression could be a
statement:
\begin{display}1 + 2 / x\end{display}
\noindent{}is a totally legit statement even though absolutely nothing will happen.
is a totally legit statement even though absolutely nothing will happen.
Why? Because in C, expressions could have side-effects -- they could
change something: \begin{display}{1 + 2 / callfunc(12)}\end{display}

\noindent{}Because \func{callfunc()} might just do something useful.
Because \func{callfunc()} might just do something useful.
Once you allow any expression to be a statement, you might as well allow
the assignment operator (=) inside expressions. That's why C lets you do
things like: \lstinline{callfunc(x = 2)}
Expand Down
4 changes: 2 additions & 2 deletions go-basics.tex
Expand Up @@ -85,7 +85,7 @@ \section{Compiling and running code}
\pr 6l -o helloworld helloworld.6 \qquad\rem{# linking stage}
\end{display}

\noindent{}For 32 bit you should use \prog{8g} and \prog{8l}, this will then
For 32 bit you should use \prog{8g} and \prog{8l}, this will then
generate \prog{helloworld.8}.\footnote{This is the only thing you will
need to change when you are cross compiling. Just use a different
compiler and you are done.}
Expand Down Expand Up @@ -212,7 +212,7 @@ \subsection{Strings}
\begin{lstlisting}
var s string = "hello"; s[0] = 'c'
\end{lstlisting}
\noindent{}To do this in Go you will need the following:
To do this in Go you will need the following:
\begin{lstlisting}
s := "hello"
c := []int(s) |\longremark{Convert \texttt{s} to an array, see %
Expand Down
1 change: 0 additions & 1 deletion go-beyond.tex
@@ -1,6 +1,5 @@
\epi{\lstinline{fmt.Printf("\%p", i)}}{Printing the address of a pointer in Go.}
\noindent

\subsection{Nil value}
A reference to nothing is represented in Go as \lstinline{nil}. This is
different than a zero value. \todo{nil only for references?}
Expand Down
16 changes: 14 additions & 2 deletions go-functions.tex
Expand Up @@ -277,9 +277,21 @@ \section{Variadic parameters}
Functions that take variadic parameters are functions that have a
variable number of parameters. In Go this is done as follows.
Firstly you need to declare your function to take variadic arguments:
\begin{lstlisting}[caption=Variadac parameters]
func myfunc(arg ... int) {}
\end{lstlisting}
The \lstinline{arg ... int} instructs Go to see this as a function that
takes a variable number of arguments. Note that all these arguments
have the type \type{int}. Inside your function's body the variable
\var{arg} is a slice of \type{int}s:
\begin{lstlisting}
for _, n := range arg {
fmt.Printf("And the number is: %d\n", n)
}
\end{lstlisting}

Secondly you must receive and unwind the arguments. A variadic
djsdjk TODO(miekg)
If you don't specify the type of the variadac argument it defaults to the
empty interface \var{interface\{\}}.

\section{Functions as values}
\label{sec:functions as values}
Expand Down
10 changes: 5 additions & 5 deletions go-intro.tex
Expand Up @@ -33,15 +33,15 @@
\textbf{Q1}. (4) A map function \ldots
\end{verse}

\noindent gives a question numbered \textbf{Q1} of a level 4 difficulty, concerning a
gives a question numbered \textbf{Q1} of a level 4 difficulty, concerning a
\func{map()}-function. The answers are included after the exercises on a
new page.
The numbering and setup of the answers is identical to the
exercises, except that an answer starts with \textbf{A$n$}, where the
number $n$ corresponds with the number of the exercise.

\begin{lbar}
\noindent{}The Go language is a young language and
The Go language is a young language and
features are still added or even \emph{removed}. It
may be possible that some text is outdated when you
read it. It is also
Expand All @@ -50,7 +50,7 @@
date with respect to the latest Go release.
An effort has been made to create "future proof" code examples.
\end{lbar}
\noindent{}The following convention is used throughout this book:
The following convention is used throughout this book:
\begin{itemize}
\item Code is displayed in \prog{DejaVu mono};
\item Keywords are displayed in \key{DejaVu mono bold};
Expand All @@ -69,7 +69,7 @@ \section{Official documentation}
a Go program called \prog{godoc}.}

\begin{lbar}
\noindent Didn't read those documents? Go read them now and stop wasting your time
Didn't read those documents? Go read them now and stop wasting your time
with this one.
\end{lbar}

Expand Down Expand Up @@ -198,7 +198,7 @@ \section{Origins}
invented QuickSort \cite{Quicksort}.

\begin{lbar}
\noindent{}Go is the first C--like language that is widely available,
Go is the first C--like language that is widely available,
runs on many
different platforms and makes concurrency easy (or easier).
\end{lbar}
Expand Down
4 changes: 2 additions & 2 deletions go-packages.tex
Expand Up @@ -32,13 +32,13 @@

\noindent\lstinline{fmt.Printf("Is %d even? %v\n", i, even.uneven(i))}

\noindent We get an error when compiling, because we are trying to use a
We get an error when compiling, because we are trying to use a
\emph{private} function:
\begin{display}
myeven.go:7: cannot refer to unexported name even.uneven
myeven.go:7: undefined: even.uneven
\end{display}
\noindent{}To summarise:
To summarise:
\begin{itemize}
\item Public functions have a name \emph{starting} with a Capital
Letter;
Expand Down

0 comments on commit f800954

Please sign in to comment.