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

Commit

Permalink
move the average function to the correct place
Browse files Browse the repository at this point in the history
  • Loading branch information
miekg committed Jan 31, 2011
1 parent 5ea7e22 commit f9dde2f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ex-unsorted/ex-average.tex → ex-functions/ex-average.tex
Expand Up @@ -6,5 +6,5 @@

\begin{Answer}
\Question The following function calculates the average.
\lstinputlisting[caption=Average function in Go,linerange={3,14}]{ex-unsorted/src/ave.go}
\lstinputlisting[caption=Average function in Go,linerange={3,14}]{ex-functions/src/ave.go}
\end{Answer}
File renamed without changes.
2 changes: 2 additions & 0 deletions ex-unsorted/ex-numbercruncher.tex
Expand Up @@ -25,6 +25,8 @@

\begin{Answer}
\Question
The following is one possibility. It uses recursion and backtracking to get
an answer.
\lstinputlisting[caption=Number cruncher,
basicstyle=\tiny\ttfamily]{ex-unsorted/src/permrec.go}

Expand Down
3 changes: 2 additions & 1 deletion ex-unsorted/ex-quine.tex
Expand Up @@ -5,7 +5,8 @@
\end{Exercise}

\begin{Answer}
\Question The following Quine is from Russ Cox:
\Question
The following Quine is from Russ Cox:
\begin{lstlisting}
/* Go quine */
package main
Expand Down
12 changes: 12 additions & 0 deletions go-functions.tex
Expand Up @@ -37,6 +37,18 @@
"\titleref{sec:functions as values}" on page \pageref{sec:functions as values}
in this chapter.

Recursive functions just work as in other languages:
\begin{lstlisting}[caption=Recursive function]
func rec(i int) {
if i == 10 {
return
}
rec(i+1)
fmt.Printf("%d ", i)
}
\end{lstlisting}
This prints \texttt{9 8 7 6 5 4 3 2 1 0}.

\section{Scope}
Variables declared outside any functions are \first{global}{scope!local} in Go, those
defined in functions are \first{local}{scope!local} to those functions. If names overlap --- a
Expand Down

0 comments on commit f9dde2f

Please sign in to comment.