changeset 11226:16d744cce38c

deprecate the dispatch function
author John W. Eaton <jwe@octave.org>
date Wed, 10 Nov 2010 16:04:31 -0500
parents 8d8e10058df6
children 84846912f3c1
files ChangeLog NEWS scripts/ChangeLog scripts/deprecated/dispatch.m scripts/deprecated/module.mk src/ChangeLog src/DLD-FUNCTIONS/__dispatch__.cc src/DLD-FUNCTIONS/dispatch.cc src/DLD-FUNCTIONS/module-files
diffstat 8 files changed, 132 insertions(+), 117 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-11-10  John W. Eaton  <jwe@octave.org>
+
+	* NEWS: Update deprecated function list with dispatch.
+
 2010-11-09  Rik  <octave@nomad.inbox5.com>
 
 	* configure.ac: Fix typo where variable name was missing '$'
--- a/NEWS
+++ b/NEWS
@@ -407,8 +407,8 @@
     be removed from Octave 3.8 (or whatever version is the second major
     release after 3.4):
 
-      cellidx      fstat        values       gammai
-      betai        is_global    autocor      autocov
+      autocor  betai    dispatch  gammai     values
+      autocov  cellidx  fstat     is_global
 
 Summary of important user-visible changes for version 3.2:
 ---------------------------------------------------------
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,8 @@
+2010-11-10  John W. Eaton  <jwe@octave.org>
+
+	* deprecated/dispatch.m: Deprecate dispatch function.
+	* deprecated/module.mk (deprecated_FCN_FILES): Add it to the list.
+
 2010-11-09  John W. Eaton  <jwe@octave.org>
 
 	* help/help.m: Call missing_function_hook with output argument
new file mode 100644
--- /dev/null
+++ b/scripts/deprecated/dispatch.m
@@ -0,0 +1,105 @@
+## Copyright (C) 2010 John W. Eaton
+##
+## This file is part of Octave.
+##
+## Octave is free software; you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3 of the License, or (at
+## your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Loadable Function} {} dispatch (@var{f}, @var{r}, @var{type})
+##
+## Replace the function @var{f} with a dispatch so that function @var{r}
+## is called when @var{f} is called with the first argument of the named
+## @var{type}.  If the type is @var{any} then call @var{r} if no other type
+## matches.  The original function @var{f} is accessible using
+## @code{builtin (@var{f}, @dots{})}.
+##
+## If @var{r} is omitted, clear dispatch function associated with @var{type}.
+##
+## If both @var{r} and @var{type} are omitted, list dispatch functions
+## for @var{f}.
+## @seealso{builtin}
+## @end deftypefn
+
+## Deprecated in version 3.4
+
+function varargout = dispatch (varargin)
+
+  persistent warned = false;
+  if (! warned)
+    warned = true;
+    warning ("Octave:deprecated-function",
+             "dispatch is obsolete and will be removed from a future version of Octave; please use classes instead");
+  endif
+
+  varargout = cell (nargout, 1);
+  [ varargout{:} ] = __dispatch__ (varargin{:});
+
+endfunction
+
+
+%!test # builtin function replacement
+%! warning off Octave:deprecated-function
+%! dispatch('sin','length','string')
+%! assert(sin("abc"),3)
+%! assert(sin(0),0,10*eps); 
+%!test # 'any' function
+%! warning off Octave:deprecated-function
+%! dispatch('sin','exp','any')
+%! assert(sin(0),1,eps);
+%! assert(sin("abc"),3);
+%!test # 'builtin' function
+%! warning off Octave:deprecated-function
+%! assert(builtin('sin',0),0,eps);
+%! builtin('eval','x=1;');
+%! assert(x,1);
+%!test # clear function mapping
+%! warning off Octave:deprecated-function
+%! dispatch('sin','string')
+%! dispatch('sin','any')
+%! assert(sin(0),0,10*eps);
+%!test # oct-file replacement
+%! warning off Octave:deprecated-function
+%! dispatch('fft','length','string')
+%! assert(fft([1,1]),[2,0]);
+%! assert(fft("abc"),3)
+%! dispatch('fft','string');
+%!test # m-file replacement
+%! warning off Octave:deprecated-function
+%! dispatch('hamming','length','string')
+%! assert(hamming(1),1)
+%! assert(hamming("abc"),3)
+%! dispatch('hamming','string')
+
+%!test # override preloaded builtin
+%! warning off Octave:deprecated-function
+%! evalin('base','cos(1);');
+%! dispatch('cos','length','string')
+%! evalin('base','assert(cos("abc"),3)');
+%! evalin('base','assert(cos(0),1,eps)');
+%! dispatch('cos','string')
+%!test # override pre-loaded oct-file
+%! warning off Octave:deprecated-function
+%! evalin('base','qr(1);');
+%! dispatch('qr','length','string')
+%! evalin('base','assert(qr("abc"),3)');
+%! evalin('base','assert(qr(1),1)');
+%! dispatch('qr','string');
+%!test # override pre-loaded m-file
+%! warning off Octave:deprecated-function
+%! evalin('base','hanning(1);');
+%! dispatch('hanning','length','string')
+%! evalin('base','assert(hanning("abc"),3)');
+%! evalin('base','assert(hanning(1),1)');
+%! dispatch('hanning','string');
--- a/scripts/deprecated/module.mk
+++ b/scripts/deprecated/module.mk
@@ -8,6 +8,7 @@
   deprecated/clg.m \
   deprecated/complement.m \
   deprecated/create_set.m \
+  deprecated/dispatch.m \
   deprecated/dmult.m \
   deprecated/fstat.m \
   deprecated/gammai.m \
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
+2010-11-10  John W. Eaton  <jwe@octave.org>
+
+	* DLD-FUNCTIONS/__dispatch__.cc: Rename from dispatch.cc.
+	Move tests to scripts/deprecated/dispatch.m.
+	(F__dispatch__): Rename from Fdispatch.
+
+	* DLD-FUNCTIONS/module-files: Add __dispatch__.cc to the list.
+	Remove dispatch.cc from the list.
+
 2010-11-10  John W. Eaton  <jwe@octave.org>
 
 	* oct-parse.yy (Fbuiltin): Move here from DLD-FUNCTIONS/dispatch.cc.
rename from src/DLD-FUNCTIONS/dispatch.cc
rename to src/DLD-FUNCTIONS/__dispatch__.cc
--- a/src/DLD-FUNCTIONS/dispatch.cc
+++ b/src/DLD-FUNCTIONS/__dispatch__.cc
@@ -40,22 +40,8 @@
 #include "symtab.h"
 #include "variables.h"
 
-DEFUN_DLD (dispatch, args, nargout,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} dispatch (@var{f}, @var{r}, @var{type})\n\
-\n\
-Replace the function @var{f} with a dispatch so that function @var{r}\n\
-is called when @var{f} is called with the first argument of the named\n\
-@var{type}.  If the type is @var{any} then call @var{r} if no other type\n\
-matches.  The original function @var{f} is accessible using\n\
-@code{builtin (@var{f}, @dots{})}.\n\
-\n\
-If @var{r} is omitted, clear dispatch function associated with @var{type}.\n\
-\n\
-If both @var{r} and @var{type} are omitted, list dispatch functions\n\
-for @var{f}.\n\
-@seealso{builtin}\n\
-@end deftypefn")
+DEFUN_DLD (__dispatch__, args, nargout,
+  "Undocumented internal function")
 {
   octave_value retval;
 
@@ -71,7 +57,7 @@
 
           if (error_state)
             {
-              error ("dispatch: expecting first argument to be function name");
+              error ("__dispatch__: expecting first argument to be function name");
               return retval;
             }
         }
@@ -82,7 +68,7 @@
 
           if (error_state)
             {
-              error ("dispatch: expecting second argument to be function name");
+              error ("__dispatch__: expecting second argument to be function name");
               return retval;
             }
         }
@@ -93,7 +79,7 @@
 
           if (error_state)
             {
-              error ("dispatch: expecting third argument to be type name");
+              error ("__dispatch__: expecting third argument to be type name");
               return retval;
             }
         }
@@ -144,98 +130,3 @@
 
   return retval;
 }
-
-/*
-
-%!test # builtin function replacement
-%! dispatch('sin','length','string')
-%! assert(sin("abc"),3)
-%! assert(sin(0),0,10*eps); 
-%!test # 'any' function
-%! dispatch('sin','exp','any')
-%! assert(sin(0),1,eps);
-%! assert(sin("abc"),3);
-%!test # 'builtin' function
-%! assert(builtin('sin',0),0,eps);
-%! builtin('eval','x=1;');
-%! assert(x,1);
-%!test # clear function mapping
-%! dispatch('sin','string')
-%! dispatch('sin','any')
-%! assert(sin(0),0,10*eps);
-%!test # oct-file replacement
-%! dispatch('fft','length','string')
-%! assert(fft([1,1]),[2,0]);
-%! assert(fft("abc"),3)
-%! dispatch('fft','string');
-%!test # m-file replacement
-%! dispatch('hamming','length','string')
-%! assert(hamming(1),1)
-%! assert(hamming("abc"),3)
-%! dispatch('hamming','string')
-
-%!test # override preloaded builtin
-%! evalin('base','cos(1);');
-%! dispatch('cos','length','string')
-%! evalin('base','assert(cos("abc"),3)');
-%! evalin('base','assert(cos(0),1,eps)');
-%! dispatch('cos','string')
-%!test # override pre-loaded oct-file
-%! evalin('base','qr(1);');
-%! dispatch('qr','length','string')
-%! evalin('base','assert(qr("abc"),3)');
-%! evalin('base','assert(qr(1),1)');
-%! dispatch('qr','string');
-%!test # override pre-loaded m-file
-%! evalin('base','hanning(1);');
-%! dispatch('hanning','length','string')
-%! evalin('base','assert(hanning("abc"),3)');
-%! evalin('base','assert(hanning(1),1)');
-%! dispatch('hanning','string');
-
-## The following tests have been disabled because creating functions
-## on the fly causes trouble (filesystem timestamp resolution?) and so
-## leads people to complain about the failed tests when the dispatch
-## mechanism is working fine, but it is really the creation of the
-## functions that is failing.  And anyway, this method of function
-## dispatch should be considered obsolete and probably removed from
-## Octave now that we have classes.
-##
-## FIXME I would rather not create dispatch_x/dispatch_y
-## in the current directory!  I don't want them installed accidentally.
-## 
-## %!function echo_to_file (str, name)
-## %!  fid = fopen (name, 'w');
-## %!  if (fid != -1)
-## %!    fprintf (fid, str);
-## %!    fprintf (fid, '\n');
-## %!    fclose (fid);
-## %!  endif
-## 
-## %!test # replace base m-file
-## %! echo_to_file ('function a=dispatch_x(a)', "dispatch_x.m");
-## %! dispatch('dispatch_x','length','string')
-## %! assert(dispatch_x(3),3)
-## %! assert(dispatch_x("a"),1)
-## %! sleep (2);
-## %! echo_to_file ('function a=dispatch_x(a),++a;', "dispatch_x.m");
-## %! rehash();
-## %! assert(dispatch_x(3),4)
-## %! assert(dispatch_x("a"),1)
-## %!test 
-## %! unlink("dispatch_x.m");
-## 
-## %!test # replace dispatch m-file
-## %! echo_to_file ('function a=dispatch_y(a)', "dispatch_y.m");
-## %! dispatch('hello','dispatch_y','complex scalar')
-## %! assert(hello(3i),3i)
-## %! sleep (2);
-## %! echo_to_file ('function a=dispatch_y(a),++a;', "dispatch_y.m");
-## %! rehash();
-## %! assert(hello(3i),1+3i)
-## %!test 
-## %! unlink("dispatch_y.m");
-
-FIXME add tests for preservation of mark_as_command status.
-
-*/
--- a/src/DLD-FUNCTIONS/module-files
+++ b/src/DLD-FUNCTIONS/module-files
@@ -1,5 +1,6 @@
 __contourc__.cc
 __delaunayn__.cc
+__dispatch__.cc
 __dsearchn__.cc
 __glpk__.cc
 __lin_interpn__.cc
@@ -25,7 +26,6 @@
 dassl.cc
 det.cc
 dot.cc
-dispatch.cc
 dlmread.cc
 dmperm.cc
 eig.cc