64 std::map<std::string, octave_value>
67 return std::map<std::string, octave_value> ();
75 "user-defined script",
76 "user-defined script");
80 t_parsed (static_cast<time_t> (0)),
81 t_checked (static_cast<time_t> (0)),
86 const std::string& nm,
88 const std::string& ds)
90 t_parsed (static_cast<time_t> (0)),
91 t_checked (static_cast<time_t> (0)),
99 const std::string& nm,
100 const std::string& ds)
102 t_parsed (static_cast<time_t> (0)),
103 t_checked (static_cast<time_t> (0)),
117 const std::list<octave_value_list>&,
int)
121 ::error (
"invalid use of script %s in index expression",
file_name.c_str ());
136 if (args.
length () == 0 && nargout == 0)
166 ::error (
"max_recursion_depth exceeded");
187 "user-defined function",
188 "user-defined function");
197 param_list (pl), ret_list (rl), cmd_list (cl),
198 lead_comm (), trail_comm (), file_name (),
199 location_line (0), location_column (0),
200 parent_name (), t_parsed (static_cast<time_t> (0)),
201 t_checked (static_cast<time_t> (0)),
203 num_named_args (param_list ? param_list->length () : 0),
204 subfunction (
false), inline_function (
false),
205 anonymous_function (
false), nested_function (
false),
206 class_constructor (
false), class_method (
false),
207 parent_scope (-1), local_scope (sid),
208 curr_unwind_protect_frame (0)
214 cmd_list->mark_as_function_body ();
216 if (local_scope >= 0)
288 new_eof_line = next_to_last_stmt->
line ();
289 new_eof_col = next_to_last_stmt->
column ();
292 last_stmt->
set_location (new_eof_line + 1, new_eof_col);
300 std::map<std::string, octave_value> fcns =
subfunctions ();
304 for (std::map<std::string, octave_value>::iterator p = fcns.begin ();
305 p != fcns.end (); p++)
320 std::ostringstream result;
333 return result.str ();
383 std::map<std::string, octave_value>
397 (
const std::list<std::string>&
names)
399 subfcn_names =
names;
417 const std::list<octave_value_list>& idx,
425 const std::list<octave_value_list>& idx,
427 const std::list<octave_lvalue>* lvalue_list)
435 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout;
438 idx.size () == 1 ? lvalue_list : 0);
446 error (
"%s cannot be indexed with %c", nm.c_str (), type[0]);
459 retval = retval(0).next_subsref (nargout, type, idx);
474 const std::list<octave_lvalue>* lvalue_list)
490 int nargin = args.
length ();
499 ::error (
"max_recursion_depth exceeded");
584 retval = (lvalue_list
585 ? expr->
rvalue (nargout, lvalue_list)
586 : expr->
rvalue (nargout));
625 error (
"expecting varargout to be a cell array object");
662 retval = par1->
name () == ret1->
name ();
670 octave_user_function::print_symtab_info (std::ostream& os)
const
696 const std::list<octave_lvalue> *lvalue_list)
698 if (! arg_names.
empty ())
729 if (takes_varargs ())
738 for (std::list<octave_lvalue>::const_iterator p = lvalue_list->begin ();
739 p != lvalue_list->end (); p++)
740 nbh += p->is_black_hole ();
747 for (std::list<octave_lvalue>::const_iterator
748 p = lvalue_list->begin (); p != lvalue_list->end (); p++)
750 if (p->is_black_hole ())
791 @deftypefn {Built-in Function} {} nargin ()\n\
792 @deftypefnx {Built-in Function} {} nargin (@var{fcn})\n\
793 Within a function, return the number of arguments passed to the function.\n\
794 At the top level, return the number of command line arguments passed to\n\
797 If called with the optional argument @var{fcn}, a function name or handle,\n\
798 return the declared number of arguments that the function can accept.\n\
799 If the last argument is @var{varargin} the returned value is negative.\n\
800 This feature does not work on builtin functions.\n\
801 @seealso{nargout, varargin, isargout, varargout, nthargout}\n\
806 int nargin = args.length ();
817 error (
"nargout: invalid function name: %s", name.c_str ());
829 retval = param_list ? param_list->
length () : 0;
831 retval = -1 - retval;
837 error (
"nargin: nargin information not available for builtin functions");
841 error (
"nargin: FCN must be a string or function handle");
843 else if (nargin == 0)
858 @deftypefn {Built-in Function} {} nargout ()\n\
859 @deftypefnx {Built-in Function} {} nargout (@var{fcn})\n\
860 Within a function, return the number of values the caller expects to\n\
861 receive. If called with the optional argument @var{fcn}, a function\n\
862 name or handle, return the number of declared output values that the\n\
863 function can produce. If the final output argument is @var{varargout}\n\
864 the returned value is negative.\n\
873 will cause @code{nargout} to return 0 inside the function @code{f} and\n\
880 will cause @code{nargout} to return 2 inside the function\n\
883 In the second usage,\n\
886 nargout (@@histc) \% or nargout (\"histc\")\n\
890 will return 2, because @code{histc} has two outputs, whereas\n\
897 will return -1, because @code{deal} has a variable number of outputs.\n\
899 At the top level, @code{nargout} with no argument is undefined.\n\
900 @code{nargout} does not work on builtin functions.\n\
901 @code{nargout} returns -1 for all anonymous functions.\n\
902 @seealso{nargin, varargin, isargout, varargout, nthargout}\n\
907 int nargin = args.length ();
918 error (
"nargout: invalid function name: %s", name.c_str ());
930 std::string fh_nm = fh->
fcn_name ();
948 retval = ret_list ? ret_list->
length () : 0;
951 retval = -1 - retval;
959 error (
"nargout: nargout information not available for builtin functions.");
963 error (
"nargout: FCN must be a string or function handle");
965 else if (nargin == 0)
975 error (
"nargout: invalid call at top level");
983 DEFUN (optimize_subsasgn_calls, args, nargout,
985 @deftypefn {Built-in Function} {@var{val} =} optimize_subsasgn_calls ()\n\
986 @deftypefnx {Built-in Function} {@var{old_val} =} optimize_subsasgn_calls (@var{new_val})\n\
987 @deftypefnx {Built-in Function} {} optimize_subsasgn_calls (@var{new_val}, \"local\")\n\
988 Query or set the internal flag for subsasgn method call optimizations.\n\
989 If true, Octave will attempt to eliminate the redundant copying when calling\n\
990 subsasgn method of a user-defined class.\n\
992 When called from inside a function with the @qcode{\"local\"} option, the\n\
993 variable is changed locally for the function and any subroutines it calls. \n\
994 The original variable value is restored when exiting the function.\n\
1006 return (i > 0 && table(i-1) == val);
1011 if (k !=
xround (k) || k <= 0)
1013 error (
"isargout: K must be a positive integer");
1017 return (k == 1 || k <= nargout) && !
val_in_table (ignored, k);
1022 @deftypefn {Built-in Function} {} isargout (@var{k})\n\
1023 Within a function, return a logical value indicating whether the argument\n\
1024 @var{k} will be assigned on output to a variable. If the result is false,\n\
1025 the argument has been ignored during the function call through the use of\n\
1026 the tilde (~) special output argument. Functions can use @code{isargout} to\n\
1027 avoid performing unnecessary calculations for outputs which are unwanted.\n\
1029 If @var{k} is outside the range @code{1:max (nargout)}, the function returns\n\
1030 false. @var{k} can also be an array, in which case the function works\n\
1031 element-by-element and a logical array is returned. At the top level,\n\
1032 @code{isargout} returns an error.\n\
1033 @seealso{nargout, nargin, varargin, varargout, nthargout}\n\
1038 int nargin = args.length ();
1047 error (
"isargout: internal error");
1056 if (args(0).is_scalar_type ())
1058 double k = args(0).double_value ();
1060 retval =
isargout1 (nargout1, ignored, k);
1062 else if (args(0).is_numeric_type ())
1064 const NDArray ka = args(0).array_value ();
1071 r(i) =
isargout1 (nargout1, ignored, ka(i));
1080 error (
"isargout: invalid call at top level");