RE: [classad-users] Newbie Question: Evaluation of logicalexpressions


Date: Mon, 4 Feb 2002 09:59:33 -0600 (CST)
From: Uwe Maurer <uma@xxxxxxxxxxx>
Subject: RE: [classad-users] Newbie Question: Evaluation of logicalexpressions
Thank you for your comments. 

Hmm. The reason for asking about shortcutting expression evaluation is a
vague idea of extending the built-in functions of classad with some
application specific functions that are quite expensive  to execute
(database queries, RPC calls and the like). 

So we would like to avoid unessesary execution of these functions.

Looking at the implementation of Operator::Evaluate in operator.C I could
just check, if the operation is boolean "and" or "or". If yes, _only_ the
first operand could be evaluated, checked and _only_ if necessary the second
operand could be evaluated.

Of course, the code would get less nice and straight forward as it is now.

I could subclass Operation to something like "BoolOperation" to point out
the different behaviour more clearly. I could even introduce new Operators
"and" and "or" to reflect this in the classad syntax.

Just some ideas. Does that sound reasonable? Or would you advise me to look
for something more suitable for our needs?

Thanks in advance.
Uwe

> -----Original Message-----
> From: Alain Aslag Roy [mailto:roy@xxxxxxxxxxx]
> Sent: Monday, February 04, 2002 4:18 PM
> To: solomon@xxxxxxxxxxxxxxxxxxx; classad-users@xxxxxxxxxxx
> Cc: Rajesh Raman
> Subject: Re: [classad-users] Newbie Question: Evaluation of
> logicalexpressions
> 
> 
> 
> >First of all, I don't understand your reference to operators.h.
> 
> Sorry, I meant operators.C
> 
> >I'm looking at
> >src/condor/condor_classad/operators.h, and all I see is a 
> big enum declaration
> 
> That's old ClassAds, as is your example below.
> 
> >     // test for cases when evaluation is strict w.r.t. "error" and 
> > "undefined"
> >     if (op != META_EQUAL_OP && op != META_NOT_EQUAL_OP  &&
> >         op != LOGICAL_OR_OP && op != LOGICAL_AND_OP     &&
> >         op != TERNARY_OP)
> 
> In the new operators.C, I see:
> 
> Evaluate (EvalState &state, Value &result) const
> {
>      Value   val1, val2, val3;
>      bool    valid1, valid2, valid3;
>      int     rval;
> 
>      valid1 = false;
>      valid2 = false;
>      valid3 = false;
> 
>      // Evaluate all valid children
>      if (child1) {
>          if( !child1->Evaluate (state, val1) ) {
>              result.SetErrorValue( );
>              return( false );
>          }
>          valid1 = true;
>      }
> 
>      if (child2) {
>          if( !child2->Evaluate (state, val2) ) {
>              result.SetErrorValue( );
>              return( false );
>          }
>          valid2 = true;
>      }
>      if (child3) {
>          if( !child3->Evaluate (state, val3) ) {
>              result.SetErrorValue( );
>              return( false );
>          }
>          valid3 = true;
>      }
> 
>      rval = _doOperation (operation, val1, val2, val3, 
> valid1, valid2, valid3,
>                  result, &state );
> 
>      return( rval != SIG_NONE );
> }
> 
> So all operands, are evaluated before the operation, right?
> 
> Your point about the lack of side-effects and how things are 
> evaluated is a 
> good point though.
> 
> -alain
> 
> 
Condor Classads Info:
http://www.cs.wisc.edu/condor/classad/




[← Prev in Thread] Current Thread [Next in Thread→]