changeset 15977:6535f92350ec

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.
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Thu, 24 Jan 2013 17:05:30 -0500
parents bbce6de5c0a5
children dc5d42399e89
files libinterp/octave-value/ov-fcn-inline.cc
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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 ()