number of results expected to be returned from a procedure
Within a procedure, the special name _nresults has as its value the number of variables on the left-hand side of the expression in which the procedure was called. If the procedure call did not involve an assignment, then _nresults is given the value undefined. If the procedure call is nested inside another expression, the value of _nresults is also set to `undefined`. Any time the procedure call on the right-side of an assignment is part of an expression more complicated than a simple function call, _nresults will be set to `undefined`.
Do not use _nresults with option remember or option cache. Only the first result computed is stored in the remember table. Subsequent results with the same input and a different value for _nresults will not respect the current value of _nresults. The Cache package can be used to manually manipulate and simulate a remember table that works with _nresults.
A procedure to find both the minimum and maximum of an arbitrary sequence of numbers could be written as follows.
maxmin := proc () local max, min, i;
max := _passed;
min := _passed;
for i from 2 to _npassed do
if _passed[i] > max then
max := _passed[i]
elif _passed[i] < min then
min := _passed[i]
if _nresults = 2 then
a ≔ maxmin⁡1,2,3
a,b ≔ maxmin⁡1,2,3
Download Help Document
What kind of issue would you like to report? (Optional)