grule-rule-engine icon indicating copy to clipboard operation
grule-rule-engine copied to clipboard

Why there is no way to add variable declaration inside rules?

Open vec715 opened this issue 8 months ago • 2 comments

Writing rules always limited to working only with the provided set of structures and their fields. When some function should accept some arguments we need to define them directly e.g.:

rule ... {
    when
        ...
    then
       fn.SendAlert("title", "body", "[email protected]", fn.CalculateSomethingX(), fn.CalculateSomethingY());
}

But it would be much much easier to read & maintain the rules if we can have a variable declaration:

rule ... {
    when
        ...
    then
       var x = fn.CalculateSomethingX(...);
       var y = fn.CalculateSomthingY(...);
       var receivers = ["[email protected]", "[email protected]"];
       var body = "very long long body here";
       fn.SendAlert("title", body, receivers, x, y);
}

Why this feature is unavailable? I wonder what type of limitations we have so there is no such a way to declare variables inside the rule?

vec715 avatar May 05 '25 11:05 vec715

Well, it seems you can do this, but you may meet some interesting things, check this https://github.com/hyperjumptech/grule-rule-engine/issues/481

dkkb avatar Jun 14 '25 11:06 dkkb

I think, we are trying to create a Rule engine and not to create another programming language. Thats why the GRL tries to be simple, flexible yet strict in it self. I fear, introducing self defined variable in the rule script could introduce un-necessary complexity and whole new level of bugs.

newm4n avatar Jun 30 '25 02:06 newm4n