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

Re: [HTCondor-users] class ad logic with undef (non-)equal

Yes, the  ?:  "operator" works when the first argument is a function,  so  

   fn(x) ?: y

will return the result of evaluating fn(x) if it isn't undefined and y otherwise.  But you need to write the expressions so that if f(x) is a boolean then y is also a boolean.   so this

   regexp("strfoo",MyAdd) ?: "" 

Should probably be this instead

   regexp("strfoo",MyAdd) ?: false 

Or you could put the ?: inside the function call to make sure that the regular _expression_ check never returns undefined

   regexp("strfoo", MyAdd ?: "" )


From: HTCondor-users <htcondor-users-bounces@xxxxxxxxxxx> on behalf of Thomas Hartmann <thomas.hartmann@xxxxxxx>
Sent: Wednesday, May 12, 2021 7:27 AM
To: HTCondor-Users Mail List <htcondor-users@xxxxxxxxxxx>
Subject: [HTCondor-users] class ad logic with undef (non-)equal
Hi all,

a short `undef` logic question:

I wrote a statement like
   ( Expr1 || regexp('strfoo',MyAdd) ) != true

Unfortunately, I had assumed, that the regexp macro should always
resolve to
   ( Expr1 || true/false ) != true
but Kruno pointed out, that in case the ad is undef the macro is not
defined as well - which would result in
   undef != true

So, one question would be, if there is a `?`-like operator for a boolean
non-equal comparison, that resolves in false when compared to undef?

To catch undef cases, we are going now for
   ( Expr1 || regexp('strfoo',MyAdd) ? : "" ) ) != true
but we are not sure, if `?` as operator actually catches undefs here?