Mercurial > octave-nkf
comparison libinterp/octave-value/ov-usr-fcn.cc @ 19229:23519ad614da
inputname.m: Overhaul function.
* inputname.m: Improve docstring. Put input validation first. Add BIST tests
for input validation.
* ov-usr-fcn.cc (Fnargin, Fnargout, Fisargout): Improve docstrings and
streamline seealso references.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 30 Sep 2014 15:11:23 -0700 |
parents | 4cdab2973171 |
children | cbc838b3020c |
comparison
equal
deleted
inserted
replaced
19228:5b64aee2257b | 19229:23519ad614da |
---|---|
830 | 830 |
831 DEFUN (nargin, args, , | 831 DEFUN (nargin, args, , |
832 "-*- texinfo -*-\n\ | 832 "-*- texinfo -*-\n\ |
833 @deftypefn {Built-in Function} {} nargin ()\n\ | 833 @deftypefn {Built-in Function} {} nargin ()\n\ |
834 @deftypefnx {Built-in Function} {} nargin (@var{fcn})\n\ | 834 @deftypefnx {Built-in Function} {} nargin (@var{fcn})\n\ |
835 Within a function, return the number of arguments passed to the function.\n\ | 835 Report the number of input arguments to a function.\n\ |
836 At the top level, return the number of command line arguments passed to\n\ | 836 \n\ |
837 Octave.\n\ | 837 Called from within a function, return the number of arguments passed to the\n\ |
838 function. At the top level, return the number of command line arguments\n\ | |
839 passed to Octave.\n\ | |
838 \n\ | 840 \n\ |
839 If called with the optional argument @var{fcn}---a function name or handle---\n\ | 841 If called with the optional argument @var{fcn}---a function name or handle---\n\ |
840 return the declared number of arguments that the function can accept.\n\ | 842 return the declared number of arguments that the function can accept.\n\ |
841 \n\ | 843 \n\ |
842 If the last argument to @var{fcn} is @var{varargin} the returned value is\n\ | 844 If the last argument to @var{fcn} is @var{varargin} the returned value is\n\ |
852 @result{} -3\n\ | 854 @result{} -3\n\ |
853 @end group\n\ | 855 @end group\n\ |
854 @end example\n\ | 856 @end example\n\ |
855 \n\ | 857 \n\ |
856 Programming Note: @code{nargin} does not work on built-in functions.\n\ | 858 Programming Note: @code{nargin} does not work on built-in functions.\n\ |
857 @seealso{nargout, varargin, isargout, varargout, nthargout}\n\ | 859 @seealso{nargout, narginchk, varargin, inputname}\n\ |
858 @end deftypefn") | 860 @end deftypefn") |
859 { | 861 { |
860 octave_value retval; | 862 octave_value retval; |
861 | 863 |
862 int nargin = args.length (); | 864 int nargin = args.length (); |
911 | 913 |
912 DEFUN (nargout, args, , | 914 DEFUN (nargout, args, , |
913 "-*- texinfo -*-\n\ | 915 "-*- texinfo -*-\n\ |
914 @deftypefn {Built-in Function} {} nargout ()\n\ | 916 @deftypefn {Built-in Function} {} nargout ()\n\ |
915 @deftypefnx {Built-in Function} {} nargout (@var{fcn})\n\ | 917 @deftypefnx {Built-in Function} {} nargout (@var{fcn})\n\ |
916 Within a function, return the number of values the caller expects to\n\ | 918 Report the number of output arguments from a function.\n\ |
917 receive. If called with the optional argument @var{fcn}---a function\n\ | 919 \n\ |
918 name or handle---return the number of declared output values that the\n\ | 920 Called from within a function, return the number of values the caller expects\n\ |
919 function can produce. If the final output argument is @var{varargout}\n\ | 921 to receive. At the top level, @code{nargout} with no argument is undefined\n\ |
920 the returned value is negative.\n\ | 922 and will produce an error.\n\ |
923 \n\ | |
924 If called with the optional argument @var{fcn}---a function name or\n\ | |
925 handle---return the number of declared output values that the function can\n\ | |
926 produce.\n\ | |
927 \n\ | |
928 If the final output argument is @var{varargout} the returned value is\n\ | |
929 negative.\n\ | |
921 \n\ | 930 \n\ |
922 For example,\n\ | 931 For example,\n\ |
923 \n\ | 932 \n\ |
924 @example\n\ | 933 @example\n\ |
925 f ()\n\ | 934 f ()\n\ |
950 \n\ | 959 \n\ |
951 @noindent\n\ | 960 @noindent\n\ |
952 will return -2, because @code{imread} has two outputs and the second is\n\ | 961 will return -2, because @code{imread} has two outputs and the second is\n\ |
953 @var{varargout}.\n\ | 962 @var{varargout}.\n\ |
954 \n\ | 963 \n\ |
955 At the top level, @code{nargout} with no argument is undefined and will\n\ | 964 Programming Note. @code{nargout} does not work for built-in functions and\n\ |
956 produce an error. @code{nargout} does not work for built-in functions and\n\ | |
957 returns -1 for all anonymous functions.\n\ | 965 returns -1 for all anonymous functions.\n\ |
958 @seealso{nargin, varargin, isargout, varargout, nthargout}\n\ | 966 @seealso{nargin, varargout, isargout, nthargout}\n\ |
959 @end deftypefn") | 967 @end deftypefn") |
960 { | 968 { |
961 octave_value retval; | 969 octave_value retval; |
962 | 970 |
963 int nargin = args.length (); | 971 int nargin = args.length (); |
1076 | 1084 |
1077 DEFUN (isargout, args, , | 1085 DEFUN (isargout, args, , |
1078 "-*- texinfo -*-\n\ | 1086 "-*- texinfo -*-\n\ |
1079 @deftypefn {Built-in Function} {} isargout (@var{k})\n\ | 1087 @deftypefn {Built-in Function} {} isargout (@var{k})\n\ |
1080 Within a function, return a logical value indicating whether the argument\n\ | 1088 Within a function, return a logical value indicating whether the argument\n\ |
1081 @var{k} will be assigned to a variable on output. If the result is false,\n\ | 1089 @var{k} will be assigned to a variable on output.\n\ |
1082 the argument has been ignored during the function call through the use of\n\ | 1090 \n\ |
1083 the tilde (~) special output argument. Functions can use @code{isargout} to\n\ | 1091 If the result is false, the argument has been ignored during the function\n\ |
1084 avoid performing unnecessary calculations for outputs which are unwanted.\n\ | 1092 call through the use of the tilde (~) special output argument. Functions\n\ |
1093 can use @code{isargout} to avoid performing unnecessary calculations for\n\ | |
1094 outputs which are unwanted.\n\ | |
1085 \n\ | 1095 \n\ |
1086 If @var{k} is outside the range @code{1:max (nargout)}, the function returns\n\ | 1096 If @var{k} is outside the range @code{1:max (nargout)}, the function returns\n\ |
1087 false. @var{k} can also be an array, in which case the function works\n\ | 1097 false. @var{k} can also be an array, in which case the function works\n\ |
1088 element-by-element and a logical array is returned. At the top level,\n\ | 1098 element-by-element and a logical array is returned. At the top level,\n\ |
1089 @code{isargout} returns an error.\n\ | 1099 @code{isargout} returns an error.\n\ |
1090 @seealso{nargout, nargin, varargin, varargout, nthargout}\n\ | 1100 @seealso{nargout, varargout, nthargout}\n\ |
1091 @end deftypefn") | 1101 @end deftypefn") |
1092 { | 1102 { |
1093 octave_value retval; | 1103 octave_value retval; |
1094 | 1104 |
1095 int nargin = args.length (); | 1105 int nargin = args.length (); |