# HG changeset patch # User jwe # Date 863203925 0 # Node ID da62d3b91fa3c5a9ed4352253a82c2051dc86deb # Parent 17c69c89fe932b09054ae3f42b795160ae60ff6f [project @ 1997-05-09 18:51:56 by jwe] diff -r 17c69c89fe93 -r da62d3b91fa3 NEWS --- a/NEWS Fri May 09 18:43:21 1997 +0000 +++ b/NEWS Fri May 09 18:52:05 1997 +0000 @@ -1,13 +1,21 @@ Summary of changes since version 2.0.5: -------------------------------------- + * New built-in variable `print_rhs_assign_val' controls what is + printed when an assignment expression is evaluated. If it is + zero, the value of the variable on the left hand side (after the + assignment) is printed. Nonzero, the value of the right hand side + (i.e., the result of the expression) is printed. The default + value of is zero, so the behavior is the same as in previous + versions of Octave. + * tmpnam now takes two optional arguments, DIR, and PREFIX. For example, tmpnam ("/foo", "bar-") returns a file name like "/foo/bar-10773baa". If DIR is omitted or empty, the value of the environment variable TMPDIR, or /tmp is used. If PREFIX is omitted, "oct-" is used. - * The built-in variable PWD has been removed. If you need to get + * The built-in variable `PWD' has been removed. If you need to get the value of the current working directory, use the pwd() function instead. diff -r 17c69c89fe93 -r da62d3b91fa3 src/ChangeLog --- a/src/ChangeLog Fri May 09 18:43:21 1997 +0000 +++ b/src/ChangeLog Fri May 09 18:52:05 1997 +0000 @@ -1,5 +1,11 @@ Fri May 9 07:40:59 1997 John W. Eaton + * pt-exp.cc (print_rhs_assign_val, symbols_of_pt_exp): New functions. + (Vprint_rhs_assign_val): New static variable. + (tree_simple_assignment_expression::eval): Use it to optionally + allow the rhs (which is the result) of an assignment to be printed + instead of the left. + * pt-exp.cc (tree_simple_assignment_expression::eval): Use new octave_variabl_reference::index function to handle indexing. diff -r 17c69c89fe93 -r da62d3b91fa3 src/pt-exp.cc --- a/src/pt-exp.cc Fri May 09 18:43:21 1997 +0000 +++ b/src/pt-exp.cc Fri May 09 18:52:05 1997 +0000 @@ -56,6 +56,10 @@ // Nonzero means we're breaking out of a loop or function body. extern int breaking; +// TRUE means print the right hand side of an assignment instead of +// the left. +static bool Vprint_rhs_assign_val; + // Prefix expressions. tree_prefix_expression::~tree_prefix_expression (void) @@ -520,85 +524,105 @@ octave_value tree_simple_assignment_expression::eval (bool print) { - octave_value retval; - - octave_value lhs_val; + octave_value rhs_val; if (error_state) - return retval; + return rhs_val; if (rhs) { - octave_value rhs_val = rhs->eval (); + octave_value lhs_val; - if (error_state) - { - eval_error (); - } - else if (rhs_val.is_undefined ()) + rhs_val = rhs->eval (); + + if (! error_state) { - error ("value on right hand side of assignment is undefined"); - eval_error (); - } - else - { - octave_variable_reference ult = lhs->reference (); - - if (error_state) - eval_error (); + if (rhs_val.is_undefined ()) + { + error ("value on right hand side of assignment is undefined"); + eval_error (); + } else { - if (index) + octave_variable_reference ult = lhs->reference (); + + if (error_state) + eval_error (); + else { - // Extract the arguments into a simple vector. + if (index) + { + // Extract the arguments into a simple vector. + + octave_value_list args + = index->convert_to_const_vector (); + + if (! error_state) + { + int nargin = args.length (); - octave_value_list args = index->convert_to_const_vector (); + if (nargin > 0) + { + ult.index (args); + + ult.assign (etype, rhs_val); - if (error_state) - eval_error (); + if (error_state) + eval_error (); + else if (! Vprint_rhs_assign_val) + lhs_val = ult.value (); + } + else + error ("??? invalid index list ???"); + } + else + eval_error (); + } else { - int nargin = args.length (); - - if (nargin > 0) - { - ult.index (args); - - ult.assign (etype, rhs_val); - - if (error_state) - eval_error (); - else - { - lhs_val = ult.value (); + ult.assign (etype, rhs_val); - retval = rhs_val; - } - } - else - error ("??? invalid index list ???"); + if (error_state) + eval_error (); + else if (! Vprint_rhs_assign_val) + lhs_val = ult.value (); } } - else - { - ult.assign (etype, rhs_val); - - lhs_val = ult.value (); - - retval = rhs_val; - } } } + else + eval_error (); + + if (! error_state && print) + { + if (Vprint_rhs_assign_val) + { + ostrstream buf; + + buf << lhs->name (); + + if (index) + { + buf << " ("; + tree_print_code tpc (buf); + index->accept (tpc); + buf << ")"; + } + + buf << ends; + + const char *tag = buf.str (); + + rhs_val.print_with_name (octave_stdout, tag); + + delete [] tag; + } + else + lhs_val.print_with_name (octave_stdout, 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 (octave_stdout, lhs->name ()); - - return retval; + return rhs_val; } void @@ -739,6 +763,21 @@ tw.visit_colon_expression (*this); } +static int +print_rhs_assign_val (void) +{ + Vprint_rhs_assign_val = check_preference ("print_rhs_assign_val"); + + return 0; +} + +void +symbols_of_pt_exp (void) +{ + DEFVAR (print_rhs_assign_val, 0.0, 0, print_rhs_assign_val, + "if TRUE, print the right hand side of assignments instead of the left"); +} + /* ;;; Local Variables: *** ;;; mode: C++ ***