Mercurial > hg > octave-lyh
annotate scripts/deprecated/dispatch.m @ 14227:c24833c6ebc2
Add error messages to dbtype(). Allow use of "end" keyword in linespec.
* debug.cc (dbtype): Add error messages when function not found.
Allow use of "end" keyword in linespec. Add new features to docstring.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Wed, 18 Jan 2012 21:17:14 -0800 |
parents | 72c96de7a403 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
1 ## Copyright (C) 2010-2012 John W. Eaton |
11226 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Loadable Function} {} dispatch (@var{f}, @var{r}, @var{type}) | |
21 ## | |
22 ## Replace the function @var{f} with a dispatch so that function @var{r} | |
23 ## is called when @var{f} is called with the first argument of the named | |
24 ## @var{type}. If the type is @var{any} then call @var{r} if no other type | |
25 ## matches. The original function @var{f} is accessible using | |
26 ## @code{builtin (@var{f}, @dots{})}. | |
27 ## | |
28 ## If @var{r} is omitted, clear dispatch function associated with @var{type}. | |
29 ## | |
30 ## If both @var{r} and @var{type} are omitted, list dispatch functions | |
31 ## for @var{f}. | |
32 ## @seealso{builtin} | |
33 ## @end deftypefn | |
34 | |
35 ## Deprecated in version 3.4 | |
36 | |
37 function varargout = dispatch (varargin) | |
38 | |
39 persistent warned = false; | |
40 if (! warned) | |
41 warned = true; | |
42 warning ("Octave:deprecated-function", | |
43 "dispatch is obsolete and will be removed from a future version of Octave; please use classes instead"); | |
44 endif | |
45 | |
46 varargout = cell (nargout, 1); | |
47 [ varargout{:} ] = __dispatch__ (varargin{:}); | |
48 | |
49 endfunction | |
50 | |
51 | |
52 %!test # builtin function replacement | |
53 %! dispatch('sin','length','string') | |
54 %! assert(sin("abc"),3) | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
55 %! assert(sin(0),0,10*eps); |
11227
84846912f3c1
test/fntests.m: run tests for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
11226
diff
changeset
|
56 |
11226 | 57 %!test # 'any' function |
58 %! dispatch('sin','exp','any') | |
59 %! assert(sin(0),1,eps); | |
60 %! assert(sin("abc"),3); | |
11227
84846912f3c1
test/fntests.m: run tests for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
11226
diff
changeset
|
61 |
11226 | 62 %!test # 'builtin' function |
63 %! assert(builtin('sin',0),0,eps); | |
64 %! builtin('eval','x=1;'); | |
65 %! assert(x,1); | |
11227
84846912f3c1
test/fntests.m: run tests for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
11226
diff
changeset
|
66 |
11226 | 67 %!test # clear function mapping |
68 %! dispatch('sin','string') | |
69 %! dispatch('sin','any') | |
70 %! assert(sin(0),0,10*eps); | |
11227
84846912f3c1
test/fntests.m: run tests for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
11226
diff
changeset
|
71 |
11226 | 72 %!test # oct-file replacement |
73 %! dispatch('fft','length','string') | |
74 %! assert(fft([1,1]),[2,0]); | |
75 %! assert(fft("abc"),3) | |
76 %! dispatch('fft','string'); | |
11227
84846912f3c1
test/fntests.m: run tests for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
11226
diff
changeset
|
77 |
11226 | 78 %!test # m-file replacement |
79 %! dispatch('hamming','length','string') | |
80 %! assert(hamming(1),1) | |
81 %! assert(hamming("abc"),3) | |
82 %! dispatch('hamming','string') | |
83 | |
84 %!test # override preloaded builtin | |
85 %! evalin('base','cos(1);'); | |
86 %! dispatch('cos','length','string') | |
87 %! evalin('base','assert(cos("abc"),3)'); | |
88 %! evalin('base','assert(cos(0),1,eps)'); | |
89 %! dispatch('cos','string') | |
11227
84846912f3c1
test/fntests.m: run tests for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
11226
diff
changeset
|
90 |
11226 | 91 %!test # override pre-loaded oct-file |
92 %! evalin('base','qr(1);'); | |
93 %! dispatch('qr','length','string') | |
94 %! evalin('base','assert(qr("abc"),3)'); | |
95 %! evalin('base','assert(qr(1),1)'); | |
96 %! dispatch('qr','string'); | |
11227
84846912f3c1
test/fntests.m: run tests for deprecated functions
John W. Eaton <jwe@octave.org>
parents:
11226
diff
changeset
|
97 |
11226 | 98 %!test # override pre-loaded m-file |
99 %! evalin('base','hanning(1);'); | |
100 %! dispatch('hanning','length','string') | |
101 %! evalin('base','assert(hanning("abc"),3)'); | |
102 %! evalin('base','assert(hanning(1),1)'); | |
103 %! dispatch('hanning','string'); |