<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - answers and comments on Question, subroutine calling</title>
    <link>http://www.mapleprimes.com/questions/144845-Subroutine-Calling</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Sun, 14 Jun 2026 00:56:35 GMT</lastBuildDate>
    <pubDate>Sun, 14 Jun 2026 00:56:35 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest answers and comments added to the Question, subroutine calling</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - answers and comments on Question, subroutine calling</title>
      <link>http://www.mapleprimes.com/questions/144845-Subroutine-Calling</link>
    </image>
    <item>
      <title>Alternatives</title>
      <link>http://www.mapleprimes.com/questions/144845-Subroutine-Calling?ref=Feed:MaplePrimes:subroutine calling:Comments#answer144848</link>
      <itunes:summary>&lt;p&gt;There are a few ways you can do this with Maple. &amp;nbsp;One is to mimic Matlab's multiple output method. &amp;nbsp;For example&lt;/p&gt;
&lt;pre&gt;MyProc := proc(x) return ( x, x+1, x^2 ); end proc:&lt;br&gt;(a,b,c) := MyProc(3);&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a, b, c := 3,4,9&lt;/pre&gt;
&lt;p&gt;The variables a, b, and c are now assigned 3, 4, and 9, respectively.&lt;/p&gt;
&lt;p&gt;That isn't, however, necessarily the best approach, particularly if you are dealing with Matrices. You might be better off passing the output Matrices to the procedure as arguments and have the procedure operate on them directly. &amp;nbsp;For example&lt;/p&gt;
&lt;pre&gt;MyProc := proc(A :: Matrix, B::Matrix, C::Matrix) &lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;B[..,..] := A^2;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;C[..,..] := A+B;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;NULL;&lt;br&gt;end proc:&lt;br&gt;X := &amp;lt;1,2;3,4&amp;gt;: Y := Matrix(2): Z := Matrix(2):&lt;br&gt;MyProc(X,Y,Z):&lt;br&gt;Y,Z;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[ 7 &amp;nbsp;10] &amp;nbsp; [8&amp;nbsp; 12]&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[ &amp;nbsp; &amp;nbsp;  ], &amp;nbsp;[ &amp;nbsp; &amp;nbsp; ]&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[15  22]  &amp;nbsp;[18 26]&lt;/pre&gt;</itunes:summary>
      <description>&lt;p&gt;There are a few ways you can do this with Maple. &amp;nbsp;One is to mimic Matlab's multiple output method. &amp;nbsp;For example&lt;/p&gt;
&lt;pre&gt;MyProc := proc(x) return ( x, x+1, x^2 ); end proc:&lt;br&gt;(a,b,c) := MyProc(3);&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a, b, c := 3,4,9&lt;/pre&gt;
&lt;p&gt;The variables a, b, and c are now assigned 3, 4, and 9, respectively.&lt;/p&gt;
&lt;p&gt;That isn't, however, necessarily the best approach, particularly if you are dealing with Matrices. You might be better off passing the output Matrices to the procedure as arguments and have the procedure operate on them directly. &amp;nbsp;For example&lt;/p&gt;
&lt;pre&gt;MyProc := proc(A :: Matrix, B::Matrix, C::Matrix) &lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;B[..,..] := A^2;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;C[..,..] := A+B;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;NULL;&lt;br&gt;end proc:&lt;br&gt;X := &amp;lt;1,2;3,4&amp;gt;: Y := Matrix(2): Z := Matrix(2):&lt;br&gt;MyProc(X,Y,Z):&lt;br&gt;Y,Z;&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[ 7 &amp;nbsp;10] &amp;nbsp; [8&amp;nbsp; 12]&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[ &amp;nbsp; &amp;nbsp;  ], &amp;nbsp;[ &amp;nbsp; &amp;nbsp; ]&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[15  22]  &amp;nbsp;[18 26]&lt;/pre&gt;</description>
      <guid>144848</guid>
      <pubDate>Thu, 21 Mar 2013 05:54:27 Z</pubDate>
      <itunes:author>Joe Riel</itunes:author>
      <author>Joe Riel</author>
    </item>
    <item>
      <title>New syntax?</title>
      <link>http://www.mapleprimes.com/questions/144845-Subroutine-Calling?ref=Feed:MaplePrimes:subroutine calling:Comments#comment144850</link>
      <itunes:summary>&lt;p&gt;Does this line have a typo?&lt;/p&gt;
&lt;p&gt;X := : Y := Matrix(2): Z := Matrix(2):&lt;br&gt;&lt;br&gt;Or is there some new syntax that I'm not aware of?&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;Does this line have a typo?&lt;/p&gt;
&lt;p&gt;X := : Y := Matrix(2): Z := Matrix(2):&lt;br&gt;&lt;br&gt;Or is there some new syntax that I'm not aware of?&lt;/p&gt;</description>
      <guid>144850</guid>
      <pubDate>Thu, 21 Mar 2013 06:19:09 Z</pubDate>
      <itunes:author>Carl Love</itunes:author>
      <author>Carl Love</author>
    </item>
    <item>
      <title>sort of</title>
      <link>http://www.mapleprimes.com/questions/144845-Subroutine-Calling?ref=Feed:MaplePrimes:subroutine calling:Comments#comment144851</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/144845-Subroutine-Calling#comment144850"&gt;@Carl Love&lt;/a&gt;&amp;nbsp;Don/t know that I'd label it a typo. I used angle brackets to assign a Matrix, preformatted the block, submitted, then later edited the post to fix an actual typo, elsewhere. That invariably elides angle brackets---I invariably forget. &amp;nbsp;Fixed it. &amp;nbsp;Thanks.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/144845-Subroutine-Calling#comment144850"&gt;@Carl Love&lt;/a&gt;&amp;nbsp;Don/t know that I'd label it a typo. I used angle brackets to assign a Matrix, preformatted the block, submitted, then later edited the post to fix an actual typo, elsewhere. That invariably elides angle brackets---I invariably forget. &amp;nbsp;Fixed it. &amp;nbsp;Thanks.&lt;/p&gt;</description>
      <guid>144851</guid>
      <pubDate>Thu, 21 Mar 2013 06:40:03 Z</pubDate>
      <itunes:author>Joe Riel</itunes:author>
      <author>Joe Riel</author>
    </item>
    <item>
      <title>multiple assignment</title>
      <link>http://www.mapleprimes.com/questions/144845-Subroutine-Calling?ref=Feed:MaplePrimes:subroutine calling:Comments#comment144853</link>
      <itunes:summary>&lt;p&gt;I would agree with Joe, that you can probably get what you want by using multiple return values from the procedure, combined with multiple &lt;a href="http://www.maplesoft.com/support/help/Maple/view.aspx?path=assignment"&gt;assignment&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;At the risk of adding irrelevant detail... Note that you have a choice in handling multiple return values (ie. an expression sequence) from a procedure. You can match it with an equal number of names on the LHS of the assignment statement. Or you can assign the whole sequence to a single name.&lt;/p&gt;
&lt;pre&gt;restart:

f := proc(x)
     return x, x^2, x^3;
end proc:

r1, r2, r3 := f(3);

                           r1, r2, r3 := 3, 9, 27

r2;

                                      9

s := f(4);

                               s := 4, 16, 64

s;

                                  4, 16, 64

s[2];

                                     16
&lt;/pre&gt;
&lt;p&gt;If you really want to get fancy you can use a feature of procedures to distinguish the number of names on the LHS of an assignment statement in which the procedure gets called. This is related only indirectly to your question, and I mention it mostly because it's not so easy to discover. See the help-page for&amp;nbsp;&lt;a href="http://www.maplesoft.com/support/help/AddOns/view.aspx?path=nresults"&gt;nresults&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;restart:

f := proc(x)
   if _nresults = 1 then
      return x;
   elif _nresults = 2 then
      return x, x^2;
   else
      return x, x^2, x^3;
   end if;
end proc:

r1, r2, r3 := f(3);

                           r1, r2, r3 := 3, 9, 27

p1, p2 := f(4);

                               p1, p2 := 4, 16

p2;

                                     16

s := f(5);

                                   s := 5
s;

                                      5
&lt;/pre&gt;
&lt;!--break--&gt;
&lt;p&gt;acer&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;I would agree with Joe, that you can probably get what you want by using multiple return values from the procedure, combined with multiple &lt;a href="http://www.maplesoft.com/support/help/Maple/view.aspx?path=assignment"&gt;assignment&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;At the risk of adding irrelevant detail... Note that you have a choice in handling multiple return values (ie. an expression sequence) from a procedure. You can match it with an equal number of names on the LHS of the assignment statement. Or you can assign the whole sequence to a single name.&lt;/p&gt;
&lt;pre&gt;restart:

f := proc(x)
     return x, x^2, x^3;
end proc:

r1, r2, r3 := f(3);

                           r1, r2, r3 := 3, 9, 27

r2;

                                      9

s := f(4);

                               s := 4, 16, 64

s;

                                  4, 16, 64

s[2];

                                     16
&lt;/pre&gt;
&lt;p&gt;If you really want to get fancy you can use a feature of procedures to distinguish the number of names on the LHS of an assignment statement in which the procedure gets called. This is related only indirectly to your question, and I mention it mostly because it's not so easy to discover. See the help-page for&amp;nbsp;&lt;a href="http://www.maplesoft.com/support/help/AddOns/view.aspx?path=nresults"&gt;nresults&lt;/a&gt;.&lt;/p&gt;
&lt;pre&gt;restart:

f := proc(x)
   if _nresults = 1 then
      return x;
   elif _nresults = 2 then
      return x, x^2;
   else
      return x, x^2, x^3;
   end if;
end proc:

r1, r2, r3 := f(3);

                           r1, r2, r3 := 3, 9, 27

p1, p2 := f(4);

                               p1, p2 := 4, 16

p2;

                                     16

s := f(5);

                                   s := 5
s;

                                      5
&lt;/pre&gt;
&lt;!--break--&gt;
&lt;p&gt;acer&lt;/p&gt;</description>
      <guid>144853</guid>
      <pubDate>Thu, 21 Mar 2013 06:51:38 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
    <item>
      <title>On nothing</title>
      <link>http://www.mapleprimes.com/questions/144845-Subroutine-Calling?ref=Feed:MaplePrimes:subroutine calling:Comments#comment144863</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/144845-Subroutine-Calling#comment144853"&gt;@acer&lt;/a&gt;&amp;nbsp;Thanks for mentioning _nresults. &amp;nbsp;It is a curious creature---it seems useful, but I've never found a definitive use for it. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Amusing myself with it I wrote the following:&lt;/p&gt;
&lt;pre&gt;enough := () -&amp;gt; `if`(_nresults=undefined,NULL,seq(1.._nresults)):&lt;br&gt;(a,b,c) := enough();&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a,b,c := 1,2,3&lt;/pre&gt;
&lt;p&gt;What surprised me was&lt;/p&gt;
&lt;pre&gt;() := enough();&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; :=&lt;/pre&gt;
&lt;p&gt;That represents&lt;/p&gt;
&lt;p&gt;NULL := 'NULL'&lt;/p&gt;
&lt;p&gt;Well, sort of. &amp;nbsp;If you enter NULL := 'NULL' an error is raised. &amp;nbsp;But if you do (I'm using tty maple)&lt;/p&gt;
&lt;pre&gt;(**) interface(prettyprint=0);&lt;br&gt;(**) () := ();&lt;br&gt;NULL := 'NULL'&lt;/pre&gt;
&lt;p&gt;NULL is a protected name that is assigned the empty expression sequence. Attempting to reassign it &amp;nbsp;raises an error. What surprised me was that it was legal to assign an empty sequence to the empty sequence. I suppose that makes sense; probably that is a result of being able to assign sequences to sequences. I don't recall when that feature was introduced (quite a while ago), but suspect that () := () was not legal in earlier versions of Maple.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br&gt;&amp;nbsp;&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/144845-Subroutine-Calling#comment144853"&gt;@acer&lt;/a&gt;&amp;nbsp;Thanks for mentioning _nresults. &amp;nbsp;It is a curious creature---it seems useful, but I've never found a definitive use for it. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Amusing myself with it I wrote the following:&lt;/p&gt;
&lt;pre&gt;enough := () -&amp;gt; `if`(_nresults=undefined,NULL,seq(1.._nresults)):&lt;br&gt;(a,b,c) := enough();&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a,b,c := 1,2,3&lt;/pre&gt;
&lt;p&gt;What surprised me was&lt;/p&gt;
&lt;pre&gt;() := enough();&lt;br&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; :=&lt;/pre&gt;
&lt;p&gt;That represents&lt;/p&gt;
&lt;p&gt;NULL := 'NULL'&lt;/p&gt;
&lt;p&gt;Well, sort of. &amp;nbsp;If you enter NULL := 'NULL' an error is raised. &amp;nbsp;But if you do (I'm using tty maple)&lt;/p&gt;
&lt;pre&gt;(**) interface(prettyprint=0);&lt;br&gt;(**) () := ();&lt;br&gt;NULL := 'NULL'&lt;/pre&gt;
&lt;p&gt;NULL is a protected name that is assigned the empty expression sequence. Attempting to reassign it &amp;nbsp;raises an error. What surprised me was that it was legal to assign an empty sequence to the empty sequence. I suppose that makes sense; probably that is a result of being able to assign sequences to sequences. I don't recall when that feature was introduced (quite a while ago), but suspect that () := () was not legal in earlier versions of Maple.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br&gt;&amp;nbsp;&lt;/p&gt;</description>
      <guid>144863</guid>
      <pubDate>Thu, 21 Mar 2013 08:29:10 Z</pubDate>
      <itunes:author>Joe Riel</itunes:author>
      <author>Joe Riel</author>
    </item>
    <item>
      <title>MTM</title>
      <link>http://www.mapleprimes.com/questions/144845-Subroutine-Calling?ref=Feed:MaplePrimes:subroutine calling:Comments#comment144873</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/144845-Subroutine-Calling#comment144863"&gt;@Joe Riel&lt;/a&gt;&amp;nbsp;The only commands I can think of, offhand, that use&amp;nbsp;&lt;strong&gt;_nresults&lt;/strong&gt; are in the MTM package.&lt;/p&gt;
&lt;p&gt;Some of those instances may seem to mimic Matlab functions (especially where the corresponding top Maple command offers an optional side-effect on a name). For example, compare Maple's&amp;nbsp;&lt;a href="http://www.maplesoft.com/support/help/Maple/view.aspx?path=MTM/coeffs"&gt;MTM:-coeffs&lt;/a&gt; with Maple's&amp;nbsp;&lt;a href="http://www.maplesoft.com/support/help/Maple/view.aspx?path=coeffs"&gt;coeffs&lt;/a&gt;, and with Matlab's (Symbolic Math Toolbox)&amp;nbsp;&lt;a href="http://www.mathworks.com/help/symbolic/coeffs.html"&gt;coeffs&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;That's partly why I mentioned _nresults, because the Question touched on Matlab vs Maple programming. I don't recall, however, whether Matlab allows user-defined functions with that kind of behaviour.&lt;/p&gt;</itunes:summary>
      <description>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/questions/144845-Subroutine-Calling#comment144863"&gt;@Joe Riel&lt;/a&gt;&amp;nbsp;The only commands I can think of, offhand, that use&amp;nbsp;&lt;strong&gt;_nresults&lt;/strong&gt; are in the MTM package.&lt;/p&gt;
&lt;p&gt;Some of those instances may seem to mimic Matlab functions (especially where the corresponding top Maple command offers an optional side-effect on a name). For example, compare Maple's&amp;nbsp;&lt;a href="http://www.maplesoft.com/support/help/Maple/view.aspx?path=MTM/coeffs"&gt;MTM:-coeffs&lt;/a&gt; with Maple's&amp;nbsp;&lt;a href="http://www.maplesoft.com/support/help/Maple/view.aspx?path=coeffs"&gt;coeffs&lt;/a&gt;, and with Matlab's (Symbolic Math Toolbox)&amp;nbsp;&lt;a href="http://www.mathworks.com/help/symbolic/coeffs.html"&gt;coeffs&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;That's partly why I mentioned _nresults, because the Question touched on Matlab vs Maple programming. I don't recall, however, whether Matlab allows user-defined functions with that kind of behaviour.&lt;/p&gt;</description>
      <guid>144873</guid>
      <pubDate>Thu, 21 Mar 2013 10:43:51 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
  </channel>
</rss>