octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #64783] Default number of output arguments not


From: John W. Eaton
Subject: [Octave-bug-tracker] [bug #64783] Default number of output arguments not 1 for anonymous functions
Date: Tue, 30 Jan 2024 15:46:26 -0500 (EST)

Follow-up Comment #6, bug#64783 (group octave):

The change would probably be better here, where the special treatment is given
to functions that have a body consisting of a single expression:


diff --git a/libinterp/parse-tree/pt-eval.cc
b/libinterp/parse-tree/pt-eval.cc
--- a/libinterp/parse-tree/pt-eval.cc
+++ b/libinterp/parse-tree/pt-eval.cc
@@ -3678,6 +3678,11 @@ tree_evaluator::execute_user_function (o
               m_call_stack.set_location (stmt->line (), stmt->column ());
 
               retval = expr->evaluate_n (*this, nargout);
+
+              // Don't allow a comma-separated list to escape (see bug
#64783).
+
+              if (nargout <= 1 && retval.length () == 1 &&
retval(0).is_cs_list ())
+                retval = retval(0).list_value ();
             }
         }
       else


Yeah, we could probably use a separate file (or files) for testing anonymous
functions.

The trouble here is partly due the somewhat odd way we handle comma-separated
lists.  Instead of those objects just being pushed onto an output stack where
they would be consumed as needed, we store the whole list in a single special
octave_value object.  I didn't see a better way to do it when adding the
concept of comma-separated lists to the tree evaluator.



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?64783>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]