noolsjs / nools

Rete based rules engine written in javascript
http://noolsjs.com/
MIT License
951 stars 181 forks source link

Weird constraint parser error #152

Open Azuri opened 9 years ago

Azuri commented 9 years ago
var flow = require('nools').flow('flow', function(flow){
   flow.rule('rule', { scope:{ Math:Math } }, [Number, 'n', 'Math.floor(n*n) > 10'], function(facts){
       //...
   });
});

flow.getSession(Math.PI).match().then(function(){ });

Throws

Error: Invalid expression 'Math.floor(n*n) > 10'    
DevSide commented 8 years ago

You're right, there is a problem here.

Until this gets done, programmatically with a custom constraint, you can do:

[Number, 'n', function(facts){
  return Math.floor( facts.n *  facts.n) > 10
}]