File: return.tex

package info (click to toggle)
sollya 8.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 17,592 kB
  • sloc: ansic: 124,655; yacc: 7,543; lex: 2,440; makefile: 888; cpp: 77
file content (57 lines) | stat: -rw-r--r-- 1,845 bytes parent folder | download | duplicates (4)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
\subsection{return}
\label{labreturn}
\noindent Name: \textbf{return}\\
\phantom{aaa}indicates an expression to be returned in a procedure\\[0.2cm]
\noindent Usage: 
\begin{center}
\textbf{return} \emph{expression} : \textsf{void}\\
\end{center}
Parameters: 
\begin{itemize}
\item \emph{expression} represents the expression to be returned
\end{itemize}
\noindent Description: \begin{itemize}

\item The keyword \textbf{return} allows for returning the (evaluated) expression
   \emph{expression} at the end of a begin-end-block ({}-block) used as a
   \sollya procedure body. See \textbf{proc} for further details concerning
   \sollya procedure definitions.
     
   Statements for returning expressions using \textbf{return} are only possible
    at the end of a begin-end-block used as a \sollya procedure
    body. Only one \textbf{return} statement can be given per begin-end-block.

\item If at the end of a procedure definition using \textbf{proc} no \textbf{return}
   statement is given, a \textbf{return} \textbf{void} statement is implicitly
   added. Procedures, i.e. procedure objects, when printed out in \sollya
   defined with an implicit \textbf{return} \textbf{void} statement are displayed with
   this statement explicitly given.
\end{itemize}
\noindent Example 1: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> succ = proc(n) { var res; res := n + 1; return res; };
> succ(5);
6
> succ;
proc(n)
{
var res;
res := (n) + (1);
return res;
}
\end{Verbatim}
\end{minipage}\end{center}
\noindent Example 2: 
\begin{center}\begin{minipage}{15cm}\begin{Verbatim}[frame=single]
> hey = proc(s) { print("Hello",s); };
> hey("world");
Hello world
> hey;
proc(s)
{
print("Hello", s);
return void;
}
\end{Verbatim}
\end{minipage}\end{center}
See also: \textbf{proc} (\ref{labproc}), \textbf{void} (\ref{labvoid})