changeset 2665:02f298ddf9f6

[project @ 1997-02-08 23:47:34 by jwe]
author jwe
date Sat, 08 Feb 1997 23:47:34 +0000
parents 9ccca1037db3
children aa519c3a0523
files src/ChangeLog src/pt-exp.cc
diffstat 2 files changed, 21 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,8 @@
 Sat Feb  8 17:16:09 1997  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* pt-exp.cc (tree_simple_assignment_expression::eval): Return
+	value of RHS, but (if printing) print complete value of LHS.
+
 	* pr-output.cc (octave_print_internal): Print a new line for empty
 	string matrices.
 
--- a/src/pt-exp.cc
+++ b/src/pt-exp.cc
@@ -691,8 +691,6 @@
   return lhs->ident ();
 }
 
-// ??? FIXME ??? -- should this return the value of the RHS instead?
-
 // ??? FIXME ??? -- should octave_variable_reference::assign return
 // the right thing for us to return?
 
@@ -703,12 +701,15 @@
 
   octave_value retval;
 
+  octave_value lhs_val;
+
   if (error_state)
     return retval;
 
   if (rhs)
     {
       octave_value rhs_val = rhs->eval (false);
+
       if (error_state)
 	{
 	  eval_error ();
@@ -745,7 +746,11 @@
 			  if (error_state)
 			    eval_error ();
 			  else
-			    retval = ult.value ();
+			    {
+			      lhs_val = ult.value ();
+
+			      retval = rhs_val;
+			    }
 			}
 		      else
 			error ("??? invalid index list ???");
@@ -754,14 +759,21 @@
 	      else
 		{
 		  ult.assign (rhs_val);
-		  retval = ult.value ();
+
+		  lhs_val = ult.value ();
+
+		  retval = rhs_val;
 		}
 	    }
 	}
     }
 
-  if (! error_state && print && retval.is_defined ())
-    retval.print_with_name (lhs->name ());
+  // Return value is RHS value, but the value we print is the complete
+  // LHS value so that expressions like x(2) = 2 (for x previously
+  // undefined) print b = [ 0; 2 ], which is more Matlab-like.
+
+  if (! error_state && print && lhs_val.is_defined ())
+    lhs_val.print_with_name (lhs->name ());
 
   return retval;
 }