Mercurial > octave
comparison scripts/miscellaneous/inputname.m @ 21069:a1aadf619e3c
inputname.m: Clarify docstring.
* inputname.m: Clarify docstring. Rename output variable 's' to 'name' for
clarity.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 14 Jan 2016 08:51:44 -0800 |
parents | 516bb87ea72e |
children | a4faec57f4c8 |
comparison
equal
deleted
inserted
replaced
21068:c221ce56f774 | 21069:a1aadf619e3c |
---|---|
21 | 21 |
22 ## -*- texinfo -*- | 22 ## -*- texinfo -*- |
23 ## @deftypefn {} {} inputname (@var{n}) | 23 ## @deftypefn {} {} inputname (@var{n}) |
24 ## Return the name of the @var{n}-th argument to the calling function. | 24 ## Return the name of the @var{n}-th argument to the calling function. |
25 ## | 25 ## |
26 ## If the argument is not a simple variable name, return an empty string. | 26 ## If the argument is not a simple variable name, return an empty string. As |
27 ## @code{inputname} may only be used within a function body, not at the | 27 ## an example, a reference to a field in a structure such as @code{s.field} is |
28 ## command line. | 28 ## not a simple name and will return @qcode{""}. |
29 ## | |
30 ## @code{inputname} is only useful within a function. When used at the command | |
31 ## line it always returns an empty string. | |
29 ## @seealso{nargin, nthargout} | 32 ## @seealso{nargin, nthargout} |
30 ## @end deftypefn | 33 ## @end deftypefn |
31 | 34 |
32 function s = inputname (n) | 35 function name = inputname (n) |
33 | 36 |
34 if (nargin != 1) | 37 if (nargin != 1) |
35 print_usage (); | 38 print_usage (); |
36 endif | 39 endif |
37 | 40 |
38 s = ""; | 41 name = ""; |
39 try | 42 try |
40 s = evalin ("caller", sprintf ("__varval__ ('.argn.'){%d}", fix (n))); | 43 name = evalin ("caller", sprintf ("__varval__ ('.argn.'){%d}", fix (n))); |
41 catch | 44 catch |
42 return; | 45 return; |
43 end_try_catch | 46 end_try_catch |
44 | 47 |
45 ## For compatibility with Matlab, | 48 ## For compatibility with Matlab, |
46 ## return empty string if argument name is not a valid identifier. | 49 ## return empty string if argument name is not a valid identifier. |
47 if (! isvarname (s)) | 50 if (! isvarname (name)) |
48 s = ""; | 51 name = ""; |
49 endif | 52 endif |
50 | 53 |
51 endfunction | 54 endfunction |
52 | 55 |
53 | 56 |