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

Commit

Permalink
Tweaks to make it better
Browse files Browse the repository at this point in the history
  • Loading branch information
miekg committed May 17, 2014
1 parent 4790867 commit db5033e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion ex-basics/src/string3.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func main() {
s := "Шла Саша по шоссе"
s := "ðåぽ ai no Æl"
r := []rune(s)
copy(r[4:4+3], []rune("abc"))
fmt.Printf("Before: %s\n", s);
Expand Down
14 changes: 7 additions & 7 deletions go-basics.tex
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,8 @@ \subsection{Range}
for k, v := range list { |\longremark{Use \key{range} to loop over them. %
With each iteration \key{range} will return the index as an \type{int} and %
the key as a \type{string}, starting with 0 and ``a''.}|
// do what you want with k and v \longremark{\var{k} will have the value 0\ldots5, and %
\var{v} will loop through ``a''\ldots``f''.}
|\longremark{\var{k} will have the value 0\ldots5, and %
\var{v} will loop through ``a''\ldots``f''.}| // do what you want with k and v
}
\end{lstlisting}
\showremarks
Expand Down Expand Up @@ -685,17 +685,17 @@ \subsection{Switch}
Without \key{fallthrough}:
\begin{lstlisting}
switch i {
case 0: // empty case body
case 0: |\coderemark{empty case body}|
case 1:
f() // f is not called when i == 0!
f() |\coderemark{f is not called when i == 0!}|
}
\end{lstlisting}
And with:
\begin{lstlisting}
switch i {
case 0: fallthrough
case 1:
f() // f is called when i == 0!
f() |\coderemark{f is called when i == 0!}|
}
\end{lstlisting}
With \first{\key{default}}{keyword!default} you can specify an action
Expand All @@ -706,7 +706,7 @@ \subsection{Switch}
case 1:
f()
default:
g() // called when i is not 0 or 1
g() |\coderemark{called when i is not 0 or 1}
}
\end{lstlisting}
Cases can be presented in comma-separated lists.
Expand Down Expand Up @@ -921,9 +921,9 @@ \subsection{Slices}
0 to 3, this is thus short for: \texttt{a[0:4]}, and yields: \texttt{1, 2, %
3, 4};}|
s5 := s2[:] |\longremark{Create a slice from the slice \var{s2}, note that %
\texttt{s5} still refers to the array \texttt{a}.}|
s6 := a[2:4:5] |\longremark{Create a slice with the elements from index 3 %
to 3 \emph{and} also set the cap to 4.}|
\texttt{s5} still refers to the array \texttt{a}.}|
\end{lstlisting}
\showremarks

Expand Down
12 changes: 6 additions & 6 deletions go-functions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ \section{Deferred code}
file.Open("file")
// Do your thing
if failureX {
file.Close() |\coderemark{}|
file.Close() |\coderemark{Close() here}|
return false
}

if failureY {
file.Close() |\coderemark{}|
file.Close() |\coderemark{And here...}|
return false
}
file.Close() |\coderemark{}|
file.Close() |\coderemark{...And here}|
return true
}
\end{lstlisting}
Expand Down Expand Up @@ -229,11 +229,11 @@ \section{Variadic parameters}
\var{arg} is a slice of ints:
\begin{lstlisting}
for _, n := range arg { |\longremark{We are not interested in the index %
as returned by range, hence the use of the underscore here}|
as returned by range, hence the use of the underscore here.}|
fmt.Printf("And the number is: %d\n", n)
}
\end{lstlisting}
\listremarks
\showremarks
If you don't specify the type of the variadic argument it defaults to the
empty interface \var{interface\{\}} (see chapter
\ref{chap:interfaces}).
Expand All @@ -242,7 +242,7 @@ \section{Variadic parameters}
\begin{lstlisting}
func myfunc(arg ...int) {
myfunc2(arg...) |\coderemark{Pass it as-is}|
myfunc2(arg[:2]...) |\coderemark{Slice it}|
myfunc2(arg[:2]...)|\coderemark{Slice it}|
}
\end{lstlisting}

Expand Down
4 changes: 2 additions & 2 deletions go-setup.tex
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@
morestring=[b]',%
morestring=[b]`,%
}[]%
\lstset{language=Go,inputencoding=utf8,extendedchars=false,texcl,escapechar=\|,basicstyle=\ttfamily,keywordstyle=\normalfont,numbers=none,numberblanklines=false,showstringspaces=false,breaklines=true,numberstyle=\small\ttfamily,xleftmargin=\parindent,xrightmargin=1em,linewidth=0.98\linewidth}
\lstset{language=Go,inputencoding=utf8,extendedchars=false,texcl,escapechar=\|,basicstyle=\ttfamily,keywordstyle=\bfseries,numbers=none,numberblanklines=false,showstringspaces=false,breaklines=true,numberstyle=\small\ttfamily,xleftmargin=\parindent,xrightmargin=1em,linewidth=0.98\linewidth}
%,literate={"}{\textasciiquote}{1}}
\newcommand{\coderemark}[1]{\sffamily\qquad$\leftarrow \textit{\footnotesize #1}$}
\newcommand{\coderemark}[1]{\sffamily\normalfont\qquad$\leftarrow \textit{\footnotesize #1}$}
%% Cite style
%%\bibpunct{[}{]}{;}{s}{,}{,}
Expand Down

0 comments on commit db5033e

Please sign in to comment.