octave-maintainers
[Top][All Lists]
Advanced

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

Re: stupid Matlab-style short-circuit behavior for | and &


From: Jaroslav Hajek
Subject: Re: stupid Matlab-style short-circuit behavior for | and &
Date: Fri, 8 Oct 2010 08:16:54 +0200

On Thu, Oct 7, 2010 at 10:39 PM, John W. Eaton <address@hidden> wrote:
> On  7-Oct-2010, Jaroslav Hajek wrote:
>
> | I was thinking about sth simple like
> |
> | bool
> | tree_binary_expression::is_logically_true (const char *warn_for,
> |                                            bool bd_short_circuit)
> | {
> |   bool retval = false;
> |   if (braindamage_short_circuit
> |       && (etype == octave_value::op_el_and || etype == 
> octave_value::op_el_or))
> |     {
> |        retval = op_lhs->is_logically_true (warn_for, bd_short_circuit);
> |        if (! error_state && retval != (etype == octave_value::op_el_and))
> |          retval = op_rhs->is_logically_true (warn_for, bd_short_circuit);
> |     }
> |   else
> |     retval = tree_expression::is_logically_true (warn_for, 
> bd_short_circuit);
> |
> |   return retval;
> | }
>
> OK, but it is not quite this simple.  The short-circuit behavior only
> happens if op_lhs evaluates to a scalar, so we can't just call
> is_logically_true here, can we?  I think we need to call rvalue1 and
> see if the result is a scalar, then if it is, do the short-circuit
> evaluation.  Since op_lhs could itself be an | or & expression, we
> need to pass bd_short_circuit to rvalue1.  Or we need some way to tell
> is_logically_true to tell us that the object is logically true and also
> that it evaluated to a scalar.  Or am I missing something?

No, apparently I just didn't realize how stupid this is :) Your first
solution was probably fine.



reply via email to

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