Re: JESS: short circuit pattern matching?

"Wolfgang Laun" <[email protected]>
Newsgroups gmane.comp.java.jess
Message-ID <5965_1289507665_oABKYOa4009291_AANLkTim6=Tc=kU=MuDPy1GDZghJjyWGp=nLH39Yq=OgV@mail.gmail.com>
I'd combine the pattern matching check and the Luhn check into a
single boolean condition
  creditCardNumber ?ccn&: (and (regexp "...." ?ccn
)(Functions.isNotValidCC ?ccn))
(and) uses short circuited evaluation.
-W

On 11 November 2010 20:19, Donald Winston <[email protected]> wrote:
> If I've two rules I'd like to turn into one doing something like "fact
> pattern1 | pattern2" then if pattern1 succeeds will pattern2 be evaluated?
> Pattern2 will be a function I don't want to execute if the pattern1
> succeeds. For example could I use one rule for the following? (I'd have to
> use a less specific error message)
> (defrule VALIDATE::purchase-info-creditCardNumber
>     (declare (salience 10))
>     (page "purchase-subscription.xslt")
>     ?fact <- (purchase-info (creditCardNumber
> ~~/^((67\\d{2})|(4\\d{3})|(5[1-5]\\d{2})|(6011))(\\s?\\d{4}){3}|(3[4,7])\\d{2}\\s?\\d{6}\\s?\\d{5}$/))
> =>
>     (modify ?fact
>         (creditCardNumberError "credit card number format is invalid")
>         (has-errors TRUE)))
> (defrule VALIDATE::purchase-info-creditCardNumber-Luhn
>     (page "purchase-subscription.xslt")
>     (purchase-info (creditCardNumberError nil))
>     ?fact <- (purchase-info (creditCardNumber ?ccn&: (Functions.isNotValidCC
> ?ccn)))
> =>
>     (modify ?fact
>         (creditCardNumberError "credit card number failed Luhn algorithm")
>         (has-errors TRUE)))
> Donald Paul Winston
> [email protected]
>
>
>




--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [email protected]'
in the BODY of a message to [email protected], NOT to the list
(use your own address!) List problems? Notify [email protected].
--------------------------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.