Mercurial > octave
changeset 26118:7502fce4cd3a
str2func: eliminate optional second "global" argument
* ov-fcn-handle.cc (Fstr2func): Ignore second argument. Don't omit
local functions in search.
* NEWS: Note change.
* fminbnd.m, fminunc.m, fsolve.m, fzero.m: Don't pass "global" to strfunc.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 21 Nov 2018 14:54:22 -0500 |
parents | a6df420457ac |
children | 1dd0e16b82e3 |
files | NEWS libinterp/octave-value/ov-fcn-handle.cc scripts/optimization/fminbnd.m scripts/optimization/fminunc.m scripts/optimization/fsolve.m scripts/optimization/fzero.m |
diffstat | 6 files changed, 21 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Fri Nov 16 19:35:39 2018 -0500 +++ b/NEWS Wed Nov 21 14:54:22 2018 -0500 @@ -107,6 +107,13 @@ ** It is now possible to use files and folders containing Unicode characters in Windows. + ** The str2func function no longer accepts a second "global" argument. + This argument was typically used to allow functions that accept + function names as arguments to avoid conflicts with subfunctions or + nested functions. Instead, it's best to avoid this situation + entirely and require users to pass function handles rather than + function names. + ** New functions added in 5.0: isfile
--- a/libinterp/octave-value/ov-fcn-handle.cc Fri Nov 16 19:35:39 2018 -0500 +++ b/libinterp/octave-value/ov-fcn-handle.cc Wed Nov 21 14:54:22 2018 -0500 @@ -1853,11 +1853,11 @@ DEFMETHOD (str2func, interp, args, , doc: /* -*- texinfo -*- @deftypefn {} {} str2func (@var{fcn_name}) -@deftypefnx {} {} str2func (@var{fcn_name}, "global") Return a function handle constructed from the string @var{fcn_name}. -If the optional @qcode{"global"} argument is passed, locally visible -functions are ignored in the lookup. +Previous versions of Octave accepted an optional second argument, +@qcode{"global"}, that caused str2func to ignore locally visible +functions. This option is no longer supported. @seealso{func2str, inline, functions} @end deftypefn */) { @@ -1880,7 +1880,13 @@ retval = anon_fcn_handle; } else - retval = make_fcn_handle (nm, nargin != 2); + { + if (nargin == 2) + warning_with_id ("Octave:str2func-global-argument", + "str2func: second argument ignored"); + + retval = make_fcn_handle (nm, true); + } return retval; }
--- a/scripts/optimization/fminbnd.m Fri Nov 16 19:35:39 2018 -0500 +++ b/scripts/optimization/fminbnd.m Wed Nov 21 14:54:22 2018 -0500 @@ -101,7 +101,7 @@ endif if (ischar (fun)) - fun = str2func (fun, "global"); + fun = str2func (fun); endif displ = optimget (options, "Display", "notify");
--- a/scripts/optimization/fminunc.m Fri Nov 16 19:35:39 2018 -0500 +++ b/scripts/optimization/fminunc.m Wed Nov 21 14:54:22 2018 -0500 @@ -111,7 +111,7 @@ endif if (ischar (fcn)) - fcn = str2func (fcn, "global"); + fcn = str2func (fcn); endif xsz = size (x0);
--- a/scripts/optimization/fsolve.m Fri Nov 16 19:35:39 2018 -0500 +++ b/scripts/optimization/fsolve.m Wed Nov 21 14:54:22 2018 -0500 @@ -185,7 +185,7 @@ endif if (ischar (fcn)) - fcn = str2func (fcn, "global"); + fcn = str2func (fcn); elseif (iscell (fcn)) fcn = @(x) make_fcn_jac (x, fcn{1}, fcn{2}); endif