<?xml version="1.0" encoding="utf-8" ?> <!-- for emacs: -*- coding: utf-8 -*- --> <!-- Apache may like this line in the file .htaccess: AddCharset utf-8 .html --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head><title>making functions with multiple return values</title> <link rel="stylesheet" type="text/css" href="../../../../Macaulay2/Style/doc.css"/> </head> <body> <table class="buttons"> <tr> <td><div><a href="_making_spnew_spfunctions_spwith_spoptional_sparguments.html">next</a> | <a href="_making_spfunctions_spwith_spa_spvariable_spnumber_spof_sparguments.html">previous</a> | <a href="_making_spnew_spfunctions_spwith_spoptional_sparguments.html">forward</a> | <a href="_making_spfunctions_spwith_spa_spvariable_spnumber_spof_sparguments.html">backward</a> | <a href="___The_sp__Macaulay2_splanguage.html">up</a> | <a href="index.html">top</a> | <a href="master.html">index</a> | <a href="toc.html">toc</a> | <a href="http://www.math.uiuc.edu/Macaulay2/">Macaulay2 web site</a></div> </td> </tr> </table> <div><a href="index.html" title="">Macaulay2Doc</a> > <a href="___The_sp__Macaulay2_splanguage.html" title="">The Macaulay2 language</a> > <a href="_making_spfunctions_spwith_spmultiple_spreturn_spvalues.html" title="">making functions with multiple return values</a></div> <hr/> <div><h1>making functions with multiple return values</h1> <div><p>A function may return multiple values by returning <span>a <a href="___Sequence.html">sequence</a></span>. Multiple assignment (see <a href="__eq.html" title="assignment">=</a>) or multiple local assignment (see <a href="__co_eq.html" title="assignment of method or new local variable">:=</a>) can be used to assign the values to separate variables, if the number of values to be returned is known.</p> <table class="examples"><tr><td><pre>i1 : f = i -> (i, i^2, i^3);</pre> </td></tr> <tr><td><pre>i2 : (x,y,z) = f 3 o2 = (3, 9, 27) o2 : Sequence</pre> </td></tr> <tr><td><pre>i3 : x o3 = 3</pre> </td></tr> <tr><td><pre>i4 : y o4 = 9</pre> </td></tr> <tr><td><pre>i5 : z o5 = 27</pre> </td></tr> </table> <p>Simple assignment may be used if the number of values to be returned is unknown.</p> <table class="examples"><tr><td><pre>i6 : s = f 4 o6 = (4, 16, 64) o6 : Sequence</pre> </td></tr> <tr><td><pre>i7 : #s o7 = 3</pre> </td></tr> <tr><td><pre>i8 : s_0 o8 = 4</pre> </td></tr> <tr><td><pre>i9 : s_1 o9 = 16</pre> </td></tr> <tr><td><pre>i10 : s_2 o10 = 64</pre> </td></tr> </table> </div> </div> </body> </html>