# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1359065130 18000 # Node ID 6535f92350ec2fc677c8db79e212aa1f0813d0e4 # Parent bbce6de5c0a513f769dfaace9a5769d22aa5a718 Always give inline functions a default argument (bug #38164) * ov-fc-inline.cc (Finline): Append "x" as an input argument if none exists. Document this behaviour. Add tests. diff -r bbce6de5c0a5 -r 6535f92350ec libinterp/octave-value/ov-fcn-inline.cc --- a/libinterp/octave-value/ov-fcn-inline.cc Tue Jan 22 23:47:29 2013 -0500 +++ b/libinterp/octave-value/ov-fcn-inline.cc Thu Jan 24 17:05:30 2013 -0500 @@ -645,7 +645,8 @@ be noted that i, and j are ignored as arguments due to the\n\ ambiguity between their use as a variable or their use as an inbuilt\n\ constant. All arguments followed by a parenthesis are considered\n\ -to be functions.\n\ +to be functions. If no arguments are found, a function taking a single\n\ +argument named @code{x} will be created.\n\ \n\ If the second and subsequent arguments are character strings,\n\ they are the names of the arguments of the function.\n\ @@ -752,6 +753,10 @@ // Sort the arguments into ascii order. fargs.sort (); + + if (fargs.length () == 0) + fargs.append (std::string ("x")); + } else if (nargin == 2 && args(1).is_numeric_type ()) { @@ -825,7 +830,9 @@ %! fn = inline ("x.^2 + 1"); %!assert (feval (fn, 6), 37) %!assert (fn (6), 37) -## FIXME: Need tests for other 2 calling forms of inline() +%!assert (feval (inline ("sum (x(:))"), [1 2; 3 4]), 10) +%!assert (feval (inline ("sqrt (x^2 + y^2)", "x", "y"), 3, 4), 5) +%!assert (feval (inline ("exp (P1*x) + P2", 3), 3, 4, 5), exp(3*4) + 5) ## Test input validation %!error inline ()