annotate scripts/deprecated/dispatch.m @ 11226:16d744cce38c

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