1% Copyright The Numerical Algorithms Group Limited 1992-94. All rights reserved. 2% !! DO NOT MODIFY THIS FILE BY HAND !! Created by ht.awk. 3\newcommand{\ExitXmpTitle}{Exit} 4\newcommand{\ExitXmpNumber}{9.20} 5% 6% ===================================================================== 7\begin{page}{ExitXmpPage}{9.20 Exit} 8% ===================================================================== 9\beginscroll 10 11% 12% 13% 14% 15% 16 17 18 19A function that does not return directly to its caller has 20\spadtype{Exit} as its return type. 21The operation \spadfun{error} is an example of one which does not return 22to its caller. 23Instead, it causes a return to top-level. 24\xtc{ 25}{ 26\spadpaste{n := 0 \bound{n}} 27} 28\xtc{ 29The function \userfun{gasp} is given return type \spadtype{Exit} since it is 30guaranteed never to return a value to its caller. 31}{ 32\begin{spadsrc}[\bound{gasp}\free{n}] 33gasp(): Exit == 34 free n 35 n := n + 1 36 error "Oh no!" 37\end{spadsrc} 38} 39\xtc{ 40The return type of \userfun{half} is determined by resolving the types of 41the two branches of the \spad{if}. 42}{ 43\begin{spadsrc}[\bound{half}\free{gasp}] 44half(k) == 45 if odd? k then gasp() 46 else k quo 2 47\end{spadsrc} 48} 49\xtc{ 50Because 51\userfun{gasp} has the return type \spadtype{Exit}, 52the type of \spad{if} in \userfun{half} is resolved to be \spadtype{Integer}. 53}{ 54\spadpaste{half 4 \free{half}\bound{app1}} 55} 56\xtc{ 57}{ 58\spadpaste{half 3 \free{half app1}\bound{app2}} 59} 60\xtc{ 61}{ 62\spadpaste{n \free{app2}} 63} 64 65For functions which return no value at all, use \spadtype{Void}. 66See \downlink{``\ugUserTitle''}{ugUserPage} in Section \ugUserNumber\ignore{ugUser} and \downlink{`Void'}{VoidXmpPage}\ignore{Void} for more information. 67% 68\showBlurb{Exit} 69\endscroll 70\autobuttons 71\end{page} 72% 73