# HG changeset patch # User John W. Eaton # Date 1515444712 18000 # Node ID 07876b7127bf4f33d63f062f5f3d7a66dc3024bc # Parent 8f2c479eb125642510901cebdfa4f8e43ca38293 reorganize binding to ans in evaluator for clarity * pt-eval.cc (tree_evaluator::visit_statement): Evaluate expression first, then decide whether to bind to ans. diff -r 8f2c479eb125 -r 07876b7127bf libinterp/parse-tree/pt-eval.cc --- a/libinterp/parse-tree/pt-eval.cc Mon Jan 08 13:25:10 2018 -0500 +++ b/libinterp/parse-tree/pt-eval.cc Mon Jan 08 15:51:52 2018 -0500 @@ -2280,29 +2280,31 @@ // evaluate the expression and that should take care of // everything, binding ans as necessary? - bool do_bind_ans = false; - - if (expr->is_identifier ()) + octave_value tmp_result = evaluate (expr, 0); + + if (tmp_result.is_defined ()) { - symbol_scope scope = get_current_scope (); - - symbol_record::context_id context = scope.current_context (); - - tree_identifier *id = dynamic_cast (expr); - - do_bind_ans = (! id->is_variable (context)); + bool do_bind_ans = false; + + if (expr->is_identifier ()) + { + symbol_scope scope = get_current_scope (); + + symbol_record::context_id context + = scope.current_context (); + + tree_identifier *id + = dynamic_cast (expr); + + do_bind_ans = (! id->is_variable (context)); + } + else + do_bind_ans = (! expr->is_assignment_expression ()); + + if (do_bind_ans) + bind_ans (tmp_result, expr->print_result () + && statement_printing_enabled ()); } - else - do_bind_ans = (! expr->is_assignment_expression ()); - - octave_value tmp_result = evaluate (expr, 0); - - if (do_bind_ans && tmp_result.is_defined ()) - bind_ans (tmp_result, expr->print_result () - && statement_printing_enabled ()); - - // if (tmp_result.is_defined ()) - // result_values(0) = tmp_result; } } catch (const std::bad_alloc&)