简体   繁体   中英

How to set up predicates in KRL?

I have the following in my global block:

test = defaction(){
    if(5>10) then {
        notify("yes","yes");    
    }
}

Then I also have the following rule:

rule tester {
    select when pageview ".*"
    test();
}

I am expecting that the notify will never happen, as 5 will never be greater than 10. However, it runs on every single page. I am sure that I am doing it wrong, although it feels right.

Predicates (such as if (5>10) then are not part of the action block. As such, including predicatees in a defaction doesn't make sense. You'll have to write it more like this:

global {
    test = defaction(){
        notify("yes","yes");    
    }
}

rule tester {
    select when pageview ".*" setting ()
    if (5>10) then {
        test();
    }
}

The if...then construct fulfills the same function as, say, the every construct: it wraps the action block.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM