nargout of builtin set

2 views (last 30 days)
Nath
Nath on 17 Apr 2014
Commented: Nath on 18 Apr 2014
The function set() returns either zero output (when 3 arguments are supplied), either 1 output (when 1 argument is supplied). Hence I thought nargout(@set) was negative, since a variable number of outputs is supposed to rely on the varargout mechanism. However, nargout(@set)= 1 !
I don't understand. How can Matlab supply a function with varying number of outputs that does not use varargout ? Is it a bug in nargout ?
Thank you

Accepted Answer

Walter Roberson
Walter Roberson on 17 Apr 2014
Varying number of outputs do not need to rely on varargout. It is completely legal to have something like
function r = set(h, varargin)
....
tr = ....
if nargout > 0; r = tr; end
end
varargout is used for arguments that are not named in the output list; ndgrid() is an example where it does not make sense to have the function code name arguments.
  1 Comment
Nath
Nath on 18 Apr 2014
Very clear. Thank you very much ! It makes me realize how useless nargout(f) is for a generic functionnal programming approach (say for instance generic function decorator)

Sign in to comment.

More Answers (0)

Categories

Find more on Variables in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!