forked from miekg/gobook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.tex
34 lines (33 loc) · 1.57 KB
/
function.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
\begin{lstlisting}[caption=A function declaration,label=src:function definition]
|\begin{tikzpicture}[overlay]
\ubrace{0.8,-1.5}{0.0,-1.5}{The keyword \key{func} is used to declare a function;}
%
\ubrace{2.9,-1.5}{0.9,-1.5}{A function can optionally be bound to a specific type. %
This is called the \first{\emph{receiver}}{receiver}. A function with a receiver is %
a \index{method}{method}. This will be explored in chapter \ref{chap:interfaces};}
%
\ubrace{4.7,-1.5}{3.1,-1.5}{\emph{funcname} is the name of your function;}
%
\ubrace{6.1,-1.5}{4.9,-1.5}{The variable \var{q} of type \type{int} is %
the input parameter. The parameters are passed %
\first{\emph{pass-by-value}}{pass-by-value} meaning they are copied;}
%
\ubrace{8.1,-1.5}{6.4,-1.5}{%
The variables \var{r} and \var{s} are the %
\index{named return parameters}{named return parameters} for this function. %
Functions in Go can have multiple return values, see section %
"\titleref{sec:multiple return}" on page \pageref{sec:multiple return}. %
If you want the return %
parameters not to be named you only give the types: %
\lstinline{(int,int)}. If you have only one value to return you may omit %
the parentheses. If your function is a subroutine and does not have %
anything to return you may omit this entirely;}
%
\ubrace{11.1,-1.5}{8.4,-1.5}{This is the function's body. Note that %
\func{return} is a statement so the braces around the parameter(s) are %
optional.}
\end{tikzpicture}|
type mytype int |\coderemark{New type, see chapter \ref{chap:beyond}}|
func (p mytype) funcname(q int) (r,s int) { return 0,0 }
||
\end{lstlisting}