Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make closure replacement dynamic #10

Open
aitrusgit opened this issue Oct 5, 2017 · 2 comments
Open

Make closure replacement dynamic #10

aitrusgit opened this issue Oct 5, 2017 · 2 comments

Comments

@aitrusgit
Copy link
Contributor

aitrusgit commented Oct 5, 2017

Right now you can freely overwrite a preexistent closure in rules-js by simply providing the overwrite flag

engine.add("closure-that-changes", definition, { overwrite: true });

Then when you invoke it directly you will exercise the modified behavior

engine.process("closure-that-change", fact);

However it won't affect preexistent higher order closures which are composed with "the-closure-that-changed".

engine.process("higher-order-closure", fact); // exercise old "closure-that-changes"!!! =(
@aitrusgit
Copy link
Contributor Author

aitrusgit commented Oct 5, 2017

Just to clarify, the definition of "higher-order-closure" might be something like this

{
  "name": "higher-order-closure",
  "rules": [
      {
          "when": "always",
          "then": "closure-that-change"
      }
   ]
}

@aitrusgit
Copy link
Contributor Author

We can achieve this behavior at parser level. Instead of creating composite closures with references to real composed closures we can add a level of indirection there. Something that abides to the Closure interface but delegates process into the real one.

Simpler solution will be doing a lookup in the closure registry every time for the real one. It might be not that efficient though (assuming we exercise the process logic way more times than what we change rules).

A more efficient solution will be to provide such indirection bound to the real closure and have a way to backtrace them and change the binding every time a closure is replaced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant