-
Notifications
You must be signed in to change notification settings - Fork 9
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
Making function calls in rules #23
Comments
I'm not sure we're going in the right direction with this. Either we end up implementing a separate parser for the define clause, or we use eval again. If we go the first path, we're starting to implement an alternative to the That said, I'm not convinced we even need the complexity of doing so: In the end, the condition statement Let's assume for a moment we have the property lookup as you suggest in #22, and there is a property If we can support that, I don't see a reason why we cannot go one step further and make this an implicit property of foo e.g. as Once we got this far, we can start adding arbitrary "function handlers", including module resolutions, i.e. Then users can implement safe & trusted functions (in python) that can be called in conditions. We can do something similar in then clauses (that was the idea of |
The parser for "define" would be mostly written in #22. The only missing thing is adding function calls, but that's not a problem.
Yes, it's possible to use the property workaround where you use object methods with no arguments like you'd do with django templates. I was actually going to mentioned this, but decided I don't like this approach that much. We'll use it anyway initially, since adding function calls is trivial for current code. It may be even sufficient and we don't need this issue that much. The reason for current proposal was to keep all logic in rule definition, while relying on properties requires writing python code, and
Yes and no. It gives the same result, of course. The difference is that:
Effectively, this is variable binding to the runtime context.
This starts to look uglier and uglier :-( I think that if we want to have function calls in C-exps, they should be changed to just contain parsed node data. In fact that could be a part of #22. So we'd have something like this |
Well, it seems we both have somewhat strong ideas on this, which is a good thing as generally well argued solutions become more solid in the end. So...
Sure, I realize that - don't get me wrong, I see the merit of the Once we start that route, it will be hard to stop before we'll have implemented at least a subset of PyPy, because naturally, once we can do function calls, we'll want iterators, soon after that exception handling, context managers, indention/multi-line support, full-blown function definitions, inner functions etc... At which point it'll have made more sense to simply stick to eval in the first place and execute it in a stripped down container, or use some other ready-made secure/secure-ish python expression evaluator (there are a few around of those). If we need that, and I doubt it, we'd better opt to adopt one of these right away.
Indeed, relying on properties should require python code by design. Much like accessing properties in Django templates requires writing python code. I think what is important here is that we do such extensions by using a well defined extension pattern, and that is what the As far as the REST API goes, rule evaluation should never require more than a serialized context and the name of the ruleset as input. Rule definitions on the other hand should always be through other means, that is by delivering .egg files which of course can contain python code. We don't need the REST API to support that though (I hope that was clear from #4). That said, even then we can accept a value with type information attached to it, e.g. As for using pyrules in an "embedded" mode, i.e. directly using it from within a python application, we are not constrained by the above of course, and intermingling directly written
well let's see
Frankly, I'm not sure the latter is less ugly ... Let's regress to the initial proposal, which was along the lines of Indeed, using the |
not sensible re. evaluation, as rules can rely on other rules and need to see whatever is the current value of foo, see #3. |
The problem with making function calls now is that clauses get converted to C-expressions, and we can't really define passing args there. A possible solution would be a new
define
clause that has function definitions.For instance, let's consider evaluating code like
math.sqrt(foo) > 2
:Basically, function call results would be added to context for evaluating if conditons, but won't be stored in result context (unless we decide that we need them, but I don't see why we'd do that).
The text was updated successfully, but these errors were encountered: