2974
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if defined (__GNUG__) |
|
24 #pragma implementation |
|
25 #endif |
|
26 |
|
27 #ifdef HAVE_CONFIG_H |
|
28 #include <config.h> |
|
29 #endif |
|
30 |
|
31 #include "str-vec.h" |
|
32 |
|
33 #include <defaults.h> |
|
34 #include "defun.h" |
|
35 #include "error.h" |
|
36 #include "input.h" |
|
37 #include "oct-obj.h" |
|
38 #include "ov-usr-fcn.h" |
|
39 #include "ov.h" |
|
40 #include "pager.h" |
2985
|
41 #include "pt-jump.h" |
2974
|
42 #include "pt-misc.h" |
|
43 #include "pt-pr-code.h" |
2982
|
44 #include "pt-stmt.h" |
2974
|
45 #include "pt-walk.h" |
|
46 #include "symtab.h" |
|
47 #include "toplev.h" |
|
48 #include "unwind-prot.h" |
|
49 #include "utils.h" |
3489
|
50 #include "parse.h" |
2974
|
51 #include "variables.h" |
|
52 |
|
53 // If TRUE, variables returned from functions have default values even |
|
54 // if they are not explicitly initialized. |
|
55 static bool Vdefine_all_return_values; |
|
56 |
3131
|
57 // Maximum nesting level for functions called recursively. |
|
58 static int Vmax_recursion_depth; |
|
59 |
2974
|
60 // If TRUE, the last computed value is returned from functions that |
|
61 // don't actually define any return variables. |
|
62 static bool Vreturn_last_computed_value; |
|
63 |
|
64 // User defined functions. |
|
65 |
3219
|
66 DEFINE_OCTAVE_ALLOCATOR (octave_user_function); |
2974
|
67 |
3219
|
68 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_user_function, |
|
69 "user-defined function"); |
2974
|
70 |
|
71 // Ugh. This really needs to be simplified (code/data? |
|
72 // extrinsic/intrinsic state?). |
|
73 |
|
74 octave_user_function::octave_user_function |
|
75 (tree_parameter_list *pl, tree_parameter_list *rl, |
|
76 tree_statement_list *cl, symbol_table *st) |
3523
|
77 : octave_function (std::string (), std::string ()), |
2974
|
78 param_list (pl), ret_list (rl), cmd_list (cl), |
3665
|
79 sym_tab (st), lead_comm (), trail_comm (), |
|
80 file_name (), fcn_name (), |
3255
|
81 t_parsed (static_cast<time_t> (0)), |
|
82 t_checked (static_cast<time_t> (0)), |
|
83 system_fcn_file (false), call_depth (0), |
3165
|
84 num_named_args (0), args_passed (), num_args_passed (0), |
|
85 curr_va_arg_number (0), vr_list (0), symtab_entry (0), |
|
86 argn_sr (0), nargin_sr (0), nargout_sr (0) |
2974
|
87 { |
|
88 install_automatic_vars (); |
|
89 |
|
90 if (param_list) |
|
91 { |
|
92 num_named_args = param_list->length (); |
|
93 curr_va_arg_number = num_named_args; |
|
94 } |
|
95 } |
|
96 |
|
97 octave_user_function::~octave_user_function (void) |
|
98 { |
|
99 delete param_list; |
|
100 delete ret_list; |
|
101 delete sym_tab; |
|
102 delete cmd_list; |
|
103 delete vr_list; |
3665
|
104 delete lead_comm; |
|
105 delete trail_comm; |
2974
|
106 } |
|
107 |
|
108 octave_user_function * |
|
109 octave_user_function::define_ret_list (tree_parameter_list *t) |
|
110 { |
|
111 ret_list = t; |
|
112 |
|
113 if (ret_list && ret_list->takes_varargs ()) |
|
114 vr_list = new tree_va_return_list; |
|
115 |
|
116 return this; |
|
117 } |
|
118 |
|
119 void |
|
120 octave_user_function::stash_fcn_file_name (void) |
|
121 { |
|
122 if (fcn_name.empty ()) |
|
123 file_name = ""; |
|
124 else |
|
125 file_name = fcn_file_in_path (fcn_name); |
|
126 } |
|
127 |
|
128 void |
|
129 octave_user_function::mark_as_system_fcn_file (void) |
|
130 { |
|
131 if (! file_name.empty ()) |
|
132 { |
|
133 // We really should stash the whole path to the file we found, |
|
134 // when we looked it up, to avoid possible race conditions... |
|
135 // XXX FIXME XXX |
|
136 // |
|
137 // We probably also don't need to get the library directory |
|
138 // every time, but since this function is only called when the |
|
139 // function file is parsed, it probably doesn't matter that |
|
140 // much. |
|
141 |
3523
|
142 std::string ff_name = fcn_file_in_path (file_name); |
2974
|
143 |
3565
|
144 if (Vfcn_file_dir == ff_name.substr (0, Vfcn_file_dir.length ())) |
2974
|
145 system_fcn_file = 1; |
|
146 } |
|
147 else |
|
148 system_fcn_file = 0; |
|
149 } |
|
150 |
|
151 bool |
|
152 octave_user_function::takes_varargs (void) const |
|
153 { |
|
154 return (param_list && param_list->takes_varargs ()); |
|
155 } |
|
156 |
|
157 octave_value |
|
158 octave_user_function::octave_va_arg (void) |
|
159 { |
|
160 octave_value retval; |
|
161 |
|
162 if (curr_va_arg_number < num_args_passed) |
|
163 retval = args_passed (curr_va_arg_number++); |
|
164 else |
|
165 ::error ("va_arg: error getting arg number %d -- only %d provided", |
|
166 curr_va_arg_number + 1, num_args_passed); |
|
167 |
|
168 return retval; |
|
169 } |
|
170 |
|
171 octave_value_list |
|
172 octave_user_function::octave_all_va_args (void) |
|
173 { |
|
174 octave_value_list retval; |
|
175 |
3178
|
176 int n = num_args_passed - num_named_args; |
2974
|
177 |
3178
|
178 if (n > 0) |
|
179 { |
|
180 retval.resize (n); |
|
181 |
|
182 int k = 0; |
|
183 for (int i = num_named_args; i < num_args_passed; i++) |
|
184 retval(k++) = args_passed(i); |
|
185 } |
2974
|
186 |
|
187 return retval; |
|
188 } |
|
189 |
|
190 bool |
|
191 octave_user_function::takes_var_return (void) const |
|
192 { |
|
193 return (ret_list && ret_list->takes_varargs ()); |
|
194 } |
|
195 |
|
196 void |
|
197 octave_user_function::octave_vr_val (const octave_value& val) |
|
198 { |
|
199 assert (vr_list); |
|
200 |
|
201 vr_list->append (val); |
|
202 } |
|
203 |
|
204 void |
3523
|
205 octave_user_function::stash_function_name (const std::string& s) |
2974
|
206 { |
|
207 fcn_name = s; |
|
208 } |
|
209 |
|
210 // For unwind protect. |
|
211 |
|
212 static void |
|
213 pop_symbol_table_context (void *table) |
|
214 { |
|
215 symbol_table *tmp = static_cast<symbol_table *> (table); |
|
216 tmp->pop_context (); |
|
217 } |
|
218 |
|
219 static void |
|
220 delete_vr_list (void *list) |
|
221 { |
|
222 tree_va_return_list *tmp = static_cast<tree_va_return_list *> (list); |
|
223 tmp->clear (); |
|
224 delete tmp; |
|
225 } |
|
226 |
|
227 static void |
|
228 clear_symbol_table (void *table) |
|
229 { |
|
230 symbol_table *tmp = static_cast<symbol_table *> (table); |
|
231 tmp->clear (); |
|
232 } |
|
233 |
|
234 static void |
3239
|
235 clear_param_list (void *lst) |
|
236 { |
|
237 tree_parameter_list *tmp = static_cast<tree_parameter_list *> (lst); |
|
238 |
|
239 if (tmp) |
|
240 tmp->clear (); |
|
241 } |
|
242 |
|
243 static void |
3875
|
244 restore_args_passed (void *fcn) |
3239
|
245 { |
|
246 octave_user_function *tmp = static_cast<octave_user_function *> (fcn); |
|
247 |
|
248 if (tmp) |
3875
|
249 tmp->restore_args_passed (); |
3239
|
250 } |
|
251 |
|
252 static void |
2974
|
253 unprotect_function (void *sr_arg) |
|
254 { |
|
255 symbol_record *sr = static_cast<symbol_record *> (sr_arg); |
|
256 sr->unprotect (); |
|
257 } |
|
258 |
|
259 octave_value_list |
3933
|
260 octave_user_function::subsref (const std::string type, |
|
261 const SLList<octave_value_list>& idx, |
|
262 int nargout) |
|
263 { |
|
264 octave_value_list retval; |
|
265 |
|
266 switch (type[0]) |
|
267 { |
|
268 case '(': |
|
269 retval = do_multi_index_op (nargout, idx.front ()); |
|
270 break; |
|
271 |
|
272 case '{': |
|
273 case '.': |
|
274 { |
|
275 std::string nm = type_name (); |
|
276 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); |
|
277 } |
|
278 break; |
|
279 |
|
280 default: |
|
281 panic_impossible (); |
|
282 } |
|
283 |
|
284 return retval; |
|
285 |
|
286 // XXX FIXME XXX |
|
287 // return retval.next_subsref (type, idx); |
|
288 } |
|
289 |
|
290 octave_value_list |
3544
|
291 octave_user_function::do_multi_index_op (int nargout, |
|
292 const octave_value_list& args) |
2974
|
293 { |
|
294 octave_value_list retval; |
|
295 |
|
296 if (error_state) |
|
297 return retval; |
|
298 |
|
299 if (! cmd_list) |
|
300 return retval; |
|
301 |
|
302 int nargin = args.length (); |
|
303 |
2985
|
304 unwind_protect::begin_frame ("func_eval"); |
2974
|
305 |
|
306 unwind_protect_int (call_depth); |
|
307 call_depth++; |
|
308 |
3131
|
309 if (call_depth > Vmax_recursion_depth) |
|
310 { |
|
311 ::error ("max_recursion_limit exceeded"); |
3321
|
312 unwind_protect::run_frame ("func_eval"); |
3131
|
313 return retval; |
|
314 } |
|
315 |
2974
|
316 if (symtab_entry && ! symtab_entry->is_read_only ()) |
|
317 { |
|
318 symtab_entry->protect (); |
2985
|
319 unwind_protect::add (unprotect_function, symtab_entry); |
2974
|
320 } |
|
321 |
|
322 if (call_depth > 1) |
|
323 { |
|
324 sym_tab->push_context (); |
2985
|
325 unwind_protect::add (pop_symbol_table_context, sym_tab); |
2974
|
326 |
|
327 if (vr_list) |
|
328 { |
|
329 // Push new vr_list. |
|
330 |
|
331 unwind_protect_ptr (vr_list); |
|
332 vr_list = new tree_va_return_list; |
|
333 |
|
334 // Clear and delete the new one before restoring the old |
|
335 // one. |
|
336 |
2985
|
337 unwind_protect::add (delete_vr_list, vr_list); |
2974
|
338 } |
|
339 } |
|
340 |
|
341 if (vr_list) |
|
342 vr_list->clear (); |
|
343 |
|
344 // Force symbols to be undefined again when this function exits. |
|
345 |
2985
|
346 unwind_protect::add (clear_symbol_table, sym_tab); |
2974
|
347 |
|
348 // Save old and set current symbol table context, for |
|
349 // eval_undefined_error(). |
|
350 |
|
351 unwind_protect_ptr (curr_sym_tab); |
|
352 curr_sym_tab = sym_tab; |
|
353 |
|
354 unwind_protect_ptr (curr_function); |
|
355 curr_function = this; |
|
356 |
3875
|
357 // Save and restore args passed for recursive calls. |
2974
|
358 |
3875
|
359 save_args_passed (args); |
3239
|
360 |
3875
|
361 unwind_protect::add (::restore_args_passed, this); |
3239
|
362 |
2974
|
363 string_vector arg_names = args.name_tags (); |
|
364 |
|
365 unwind_protect_int (num_args_passed); |
|
366 num_args_passed = nargin; |
|
367 |
|
368 unwind_protect_int (curr_va_arg_number); |
|
369 |
3876
|
370 curr_va_arg_number = num_named_args; |
|
371 |
2974
|
372 if (param_list && ! param_list->varargs_only ()) |
|
373 { |
|
374 param_list->define_from_arg_vector (args); |
|
375 if (error_state) |
|
376 goto abort; |
|
377 } |
|
378 |
3239
|
379 // Force parameter list to be undefined when this function exits. |
|
380 // Doing so decrements the reference counts on the values of local |
|
381 // variables that are also named function parameters. |
|
382 |
|
383 unwind_protect::add (clear_param_list, param_list); |
|
384 |
|
385 // Force return list to be undefined when this function exits. |
|
386 // Doing so decrements the reference counts on the values of local |
|
387 // variables that are also named values returned by this function. |
|
388 |
|
389 unwind_protect::add (clear_param_list, ret_list); |
|
390 |
2974
|
391 // The following code is in a separate scope to avoid warnings from |
|
392 // G++ about `goto abort' crossing the initialization of some |
|
393 // variables. |
|
394 |
|
395 { |
|
396 bind_automatic_vars (arg_names, nargin, nargout); |
|
397 |
|
398 bool echo_commands = (Vecho_executing_commands & ECHO_FUNCTIONS); |
|
399 |
|
400 if (echo_commands) |
|
401 print_code_function_header (); |
|
402 |
|
403 // Evaluate the commands that make up the function. |
|
404 |
3489
|
405 unwind_protect_bool (evaluating_function_body); |
|
406 evaluating_function_body = true; |
|
407 |
2974
|
408 octave_value_list tmp = cmd_list->eval (); |
|
409 |
|
410 octave_value last_computed_value; |
|
411 |
|
412 if (! tmp.empty ()) |
|
413 last_computed_value = tmp(0); |
|
414 |
|
415 if (echo_commands) |
|
416 print_code_function_trailer (); |
|
417 |
2985
|
418 if (tree_return_command::returning) |
|
419 tree_return_command::returning = 0; |
2974
|
420 |
2985
|
421 if (tree_break_command::breaking) |
|
422 tree_break_command::breaking--; |
2974
|
423 |
|
424 if (error_state) |
|
425 { |
|
426 traceback_error (); |
|
427 goto abort; |
|
428 } |
|
429 |
|
430 // Copy return values out. |
|
431 |
|
432 if (ret_list) |
3871
|
433 { |
|
434 if (Vdefine_all_return_values) |
|
435 { |
|
436 octave_value tmp = builtin_any_variable ("default_return_value"); |
|
437 |
|
438 if (tmp.is_defined ()) |
|
439 ret_list->initialize_undefined_elements (tmp); |
|
440 } |
|
441 |
|
442 retval = ret_list->convert_to_const_vector (vr_list); |
|
443 } |
2974
|
444 else if (Vreturn_last_computed_value) |
|
445 retval(0) = last_computed_value; |
|
446 } |
|
447 |
|
448 abort: |
2985
|
449 unwind_protect::run_frame ("func_eval"); |
2974
|
450 |
|
451 return retval; |
|
452 } |
|
453 |
|
454 void |
|
455 octave_user_function::traceback_error (void) |
|
456 { |
|
457 if (error_state >= 0) |
|
458 error_state = -1; |
|
459 |
|
460 if (fcn_name.empty ()) |
|
461 { |
|
462 if (file_name.empty ()) |
|
463 ::error ("called from `?unknown?'"); |
|
464 else |
|
465 ::error ("called from file `%s'", file_name.c_str ()); |
|
466 } |
|
467 else |
|
468 { |
|
469 if (file_name.empty ()) |
|
470 ::error ("called from `%s'", fcn_name.c_str ()); |
|
471 else |
|
472 ::error ("called from `%s' in file `%s'", |
|
473 fcn_name.c_str (), file_name.c_str ()); |
|
474 } |
|
475 } |
|
476 |
|
477 void |
|
478 octave_user_function::accept (tree_walker& tw) |
|
479 { |
|
480 tw.visit_octave_user_function (*this); |
|
481 } |
|
482 |
|
483 void |
3933
|
484 octave_user_function::print_symtab_info (std::ostream& os) const |
|
485 { |
|
486 if (sym_tab) |
|
487 sym_tab->print_info (os); |
|
488 else |
|
489 warning ("%s: no symbol table info!", fcn_name.c_str ()); |
|
490 } |
|
491 |
|
492 void |
2974
|
493 octave_user_function::print_code_function_header (void) |
|
494 { |
|
495 tree_print_code tpc (octave_stdout, Vps4); |
|
496 |
|
497 tpc.visit_octave_user_function_header (*this); |
|
498 } |
|
499 |
|
500 void |
|
501 octave_user_function::print_code_function_trailer (void) |
|
502 { |
|
503 tree_print_code tpc (octave_stdout, Vps4); |
|
504 |
|
505 tpc.visit_octave_user_function_trailer (*this); |
|
506 } |
|
507 |
|
508 void |
|
509 octave_user_function::install_automatic_vars (void) |
|
510 { |
|
511 argn_sr = sym_tab->lookup ("argn", true); |
|
512 nargin_sr = sym_tab->lookup ("nargin", true); |
|
513 nargout_sr = sym_tab->lookup ("nargout", true); |
|
514 } |
|
515 |
|
516 void |
|
517 octave_user_function::bind_automatic_vars |
|
518 (const string_vector& arg_names, int nargin, int nargout) |
|
519 { |
|
520 if (! arg_names.empty ()) |
|
521 argn_sr->define (arg_names); |
|
522 |
|
523 nargin_sr->define (static_cast<double> (nargin)); |
|
524 nargout_sr->define (static_cast<double> (nargout)); |
|
525 } |
|
526 |
3743
|
527 DEFUNX ("va_arg", Fva_arg, args, , |
3445
|
528 "-*- texinfo -*-\n\ |
|
529 @deftypefn {Built-in Function} {} va_arg ()\n\ |
3745
|
530 Return the value of the next available argument and move the internal\n\ |
3445
|
531 pointer to the next argument. It is an error to call @code{va_arg}\n\ |
|
532 when ther eare no more arguments available, or in a function that\n\ |
|
533 has not been declared to take a variable number of parameters.\n\ |
|
534 @end deftypefn") |
2974
|
535 { |
|
536 octave_value_list retval; |
|
537 |
|
538 int nargin = args.length (); |
|
539 |
|
540 if (nargin == 0) |
|
541 { |
|
542 if (curr_function) |
|
543 { |
|
544 if (curr_function->takes_varargs ()) |
|
545 retval = curr_function->octave_va_arg (); |
|
546 else |
|
547 { |
|
548 ::error ("va_arg only valid within function taking variable"); |
|
549 ::error ("number of arguments"); |
|
550 } |
|
551 } |
|
552 else |
|
553 ::error ("va_arg only valid within function body"); |
|
554 } |
|
555 else |
|
556 print_usage ("va_arg"); |
|
557 |
|
558 return retval; |
|
559 } |
|
560 |
|
561 DEFUN (va_start, args, , |
3445
|
562 "-*- texinfo -*-\n\ |
|
563 @deftypefn {Built-in Function} {} va_start ()\n\ |
|
564 Position an internal pointer to the first unnamed argument in\n\ |
|
565 functions that have been declared to accept a variable number of\n\ |
|
566 arguments. It is an error to call @code{va_start} in a function\n\ |
|
567 that has not been declared to take a variable number of parameters.\n\ |
|
568 @end deftypefn") |
2974
|
569 { |
|
570 octave_value_list retval; |
|
571 |
|
572 int nargin = args.length (); |
|
573 |
|
574 if (nargin == 0) |
|
575 { |
|
576 if (curr_function) |
|
577 { |
|
578 if (curr_function->takes_varargs ()) |
|
579 curr_function->octave_va_start (); |
|
580 else |
|
581 { |
|
582 ::error ("va_start only valid within function taking variable"); |
|
583 ::error ("number of arguments"); |
|
584 } |
|
585 } |
|
586 else |
|
587 ::error ("va_start only valid within function body"); |
|
588 } |
|
589 else |
|
590 print_usage ("va_start"); |
|
591 |
|
592 return retval; |
|
593 } |
|
594 |
|
595 DEFUN (vr_val, args, , |
3445
|
596 "-*- texinfo -*-\n\ |
|
597 @deftypefn {Built-in Function} {} vr_val (@var{x})\n\ |
|
598 Each time this function is called, it places the value of its argument\n\ |
|
599 at the end of the list of values to return from the current\n\ |
|
600 function. Once @code{vr_val} has been called, there is no way to go\n\ |
|
601 back to the beginning of the list and rewrite any of the return\n\ |
|
602 values. This function may only be called within functions that have\n\ |
|
603 been declared to return an unspecified number of output arguments.\n\ |
|
604 @end deftypefn") |
2974
|
605 { |
|
606 octave_value_list retval; |
|
607 |
|
608 int nargin = args.length (); |
|
609 |
|
610 if (nargin == 1) |
|
611 { |
|
612 if (curr_function) |
|
613 { |
|
614 if (curr_function->takes_var_return ()) |
|
615 curr_function->octave_vr_val (args(0)); |
|
616 else |
|
617 { |
|
618 ::error ("vr_val only valid within function declared to"); |
|
619 ::error ("produce a variable number of values"); |
|
620 } |
|
621 } |
|
622 else |
|
623 ::error ("vr_val only valid within function body"); |
|
624 } |
|
625 else |
|
626 print_usage ("vr_val"); |
|
627 |
|
628 return retval; |
|
629 } |
|
630 |
|
631 static int |
|
632 define_all_return_values (void) |
|
633 { |
|
634 Vdefine_all_return_values = check_preference ("define_all_return_values"); |
|
635 |
|
636 return 0; |
|
637 } |
|
638 |
|
639 static int |
3131
|
640 max_recursion_depth (void) |
|
641 { |
|
642 Vmax_recursion_depth = check_preference ("max_recursion_depth"); |
|
643 |
|
644 return 0; |
|
645 } |
|
646 |
|
647 static int |
2974
|
648 return_last_computed_value (void) |
|
649 { |
|
650 Vreturn_last_computed_value |
|
651 = check_preference ("return_last_computed_value"); |
|
652 |
|
653 return 0; |
|
654 } |
|
655 |
|
656 void |
|
657 symbols_of_ov_usr_fcn (void) |
|
658 { |
3258
|
659 DEFVAR (default_return_value, Matrix (), 0, |
3371
|
660 "-*- texinfo -*-\n\ |
|
661 @defvr {Built-in Variable} default_return_value\n\ |
|
662 The value given to otherwise uninitialized return values if\n\ |
|
663 @code{define_all_return_values} is nonzero. The default value is\n\ |
|
664 @code{[]}.\n\ |
|
665 @end defvr"); |
2974
|
666 |
3258
|
667 DEFVAR (define_all_return_values, 0.0, define_all_return_values, |
3371
|
668 "-*- texinfo -*-\n\ |
|
669 @defvr {Built-in Variable} define_all_return_values\n\ |
|
670 If the value of @code{define_all_return_values} is nonzero, Octave\n\ |
|
671 will substitute the value specified by @code{default_return_value} for\n\ |
|
672 any return values that remain undefined when a function returns. The\n\ |
|
673 default value is 0.\n\ |
|
674 @end defvr"); |
2974
|
675 |
3258
|
676 DEFVAR (max_recursion_depth, 256.0, max_recursion_depth, |
3371
|
677 "-*- texinfo -*-\n\ |
|
678 @defvr {Built-in Variable} max_recursion_depth\n\ |
|
679 Limit the number of times a function may be called recursively.\n\ |
|
680 If the limit is exceeded, an error message is printed and control\n\ |
|
681 returns to the top level.\n\ |
|
682 \n\ |
|
683 The default value is 256.\n\ |
|
684 @end defvr"); |
3131
|
685 |
3258
|
686 DEFVAR (return_last_computed_value, 0.0, return_last_computed_value, |
3371
|
687 "-*- texinfo -*-\n\ |
|
688 @defvr {Built-in Variable} return_last_computed_value\n\ |
|
689 If the value of @code{return_last_computed_value} is true, and a\n\ |
|
690 function is defined without explicitly specifying a return value, the\n\ |
|
691 function will return the value of the last expression. Otherwise, no\n\ |
|
692 value will be returned. The default value is 0.\n\ |
|
693 \n\ |
|
694 For example, the function\n\ |
|
695 \n\ |
|
696 @example\n\ |
|
697 function f ()\n\ |
|
698 2 + 2;\n\ |
|
699 endfunction\n\ |
|
700 @end example\n\ |
|
701 \n\ |
|
702 @noindent\n\ |
|
703 will either return nothing, if the value of\n\ |
|
704 @code{return_last_computed_value} is 0, or 4, if the value of\n\ |
|
705 @code{return_last_computed_value} is nonzero.\n\ |
|
706 @end defvr"); |
2974
|
707 } |
|
708 |
|
709 /* |
|
710 ;;; Local Variables: *** |
|
711 ;;; mode: C++ *** |
|
712 ;;; End: *** |
|
713 */ |