annotate scripts/miscellaneous/inputname.m @ 20654:b65888ec820e draft default tip gccjit

dmalcom gcc jit import
author Stefan Mahr <dac922@gmx.de>
date Fri, 27 Feb 2015 16:59:36 +0100
parents d5b877b86ed4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19630
diff changeset
1 ## Copyright (C) 2004-2015 Paul Kienzle
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
2 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
4 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
6 ## under the terms of the GNU General Public License as published by
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
8 ## your option) any later version.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
9 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
13 ## General Public License for more details.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
14 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
15 ## You should have received a copy of the GNU General Public License
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
17 ## <http://www.gnu.org/licenses/>.
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
18 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
19 ## Original version by Paul Kienzle distributed as free software in the
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
20 ## public domain.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
21
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
22 ## -*- texinfo -*-
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
23 ## @deftypefn {Function File} {} inputname (@var{n})
10091
a115046d462d inputname: compatibility fix
John W. Eaton <jwe@octave.org>
parents: 7125
diff changeset
24 ## Return the name of the @var{n}-th argument to the calling function.
19229
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18201
diff changeset
25 ##
10091
a115046d462d inputname: compatibility fix
John W. Eaton <jwe@octave.org>
parents: 7125
diff changeset
26 ## If the argument is not a simple variable name, return an empty string.
19229
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18201
diff changeset
27 ## @code{inputname} may only be used within a function body, not at the
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18201
diff changeset
28 ## command line.
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18201
diff changeset
29 ## @seealso{nargin, nthargout}
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
30 ## @end deftypefn
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
31
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
32 function s = inputname (n)
7125
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
33
19229
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18201
diff changeset
34 if (nargin != 1)
7125
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
35 print_usage ();
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
36 endif
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
37
19759
5f2c0ca0ef51 Ensure that numbers passed to integer *printf format codes are integers (bug #44245).
Rik <rik@octave.org>
parents: 19731
diff changeset
38 s = evalin ("caller", sprintf ("__varval__ (\".argn.\"){%d};", fix (n)));
19229
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18201
diff changeset
39 ## For compatibility with Matlab,
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18201
diff changeset
40 ## return empty string if argument name is not a valid identifier.
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18201
diff changeset
41 if (! isvarname (s))
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18201
diff changeset
42 s = "";
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18201
diff changeset
43 endif
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18201
diff changeset
44
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
45 endfunction
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
46
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
47
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
48 ## Warning: heap big magic in the following tests!!!
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
49 ## The test function builds a private context for each
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
50 ## test, with only the specified values shared between
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
51 ## them. It does this using the following template:
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
52 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
53 ## function [<shared>] = testfn(<shared>)
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
54 ## <test>
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
55 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
56 ## To test inputname, I need a function context invoked
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
57 ## with known parameter names. So define a couple of
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
58 ## shared parameters, et voila!, the test is trivial.
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
59
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
60 %!shared hello, worldly
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
61 %!assert (inputname (1), "hello")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
62 %!assert (inputname (2), "worldly")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
63
20462
d5b877b86ed4 inputname.m: Rename BIST function foo to __foo__ to avoid name collisions.
Rik <rik@octave.org>
parents: 19759
diff changeset
64 %!function r = __foo__ (x, y)
18201
ec87e965c246 allow inputname to work correctly with feval (bug #35497)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
65 %! r = inputname (2);
ec87e965c246 allow inputname to work correctly with feval (bug #35497)
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
66 %!endfunction
20462
d5b877b86ed4 inputname.m: Rename BIST function foo to __foo__ to avoid name collisions.
Rik <rik@octave.org>
parents: 19759
diff changeset
67 %!assert (__foo__ (pi, e), "e");
d5b877b86ed4 inputname.m: Rename BIST function foo to __foo__ to avoid name collisions.
Rik <rik@octave.org>
parents: 19759
diff changeset
68 %!assert (feval (@__foo__, pi, e), "e");
19229
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18201
diff changeset
69
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18201
diff changeset
70 %!error inputname ()
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18201
diff changeset
71 %!error inputname (1,2)
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18201
diff changeset
72