krl

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.


Solution

  • 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.