Interesting!

An OPS5 parser would be a plus. Defining the rules with the JS API is a 
rather heavy.

Did the monkey eat all the bananas? I did not see them :-)

Bruno

On Tuesday, March 6, 2012 10:30:04 PM UTC+1, Douglas Martin wrote:
>
> Hi Everyone,
>
> Today I released v0.0.1 of nools <https://github.com/doug-martin/nools>, 
> a rules engine for node. I currently working on more documentation but any 
> feedback would be greatly appreciated!
>
> Here is an example of using nools to calculate fibonacci numbers.
>
> "use strict";
>
> var nools = require("../index");
>
> var Fibonacci = function (sequence, value) {
>     this.sequence = sequence;
>     this.value = value || -1;
> };
>
> var Result = function (result) {
>     this.result = result || -1;
> };
>
>
> var flow = nools.flow("Fibonacci Flow", function (flow) {
>
>     flow.rule("Recurse", {priority:1}, [
>         ["not", Fibonacci, "f", "f.sequence == 1"],
>         [Fibonacci, "f1", "f1.sequence != 1"]
>     ], function (facts) {
>         var f2 = new Fibonacci(facts.f1.sequence - 1);
>         this.assert(f2);
>     });
>
>     flow.rule("Bootstrap", [
>         Fibonacci, "f", "f.value == -1 && (f.sequence == 1 || f.sequence 
> == 2)"
>     ], function (facts) {
>         var f = facts.f;
>         f.value = 1;
>         this.modify(f);
>     });
>
>     flow.rule("Calculate", [
>         [Fibonacci, "f1", "f1.value != -1", {sequence:"s1"}],
>         [Fibonacci, "f2", "f2.value != -1 && f2.sequence == s1 + 1", 
> {sequence:"s2"}],
>         [Fibonacci, "f3", "f3.value == -1 && f3.sequence == s2 + 1"],
>         [Result, "r"]
>     ], function (facts) {
>         var f3 = facts.f3, f1 = facts.f1, f2 = facts.f2;
>         var v = f3.value = f1.value + facts.f2.value;
>         facts.r.result = v;
>         this.modify(f3);
>         this.retract(f1);
>     });
> });
>
> var r1 = new Result(),
>     session1 = flow.getSession(new Fibonacci(10), r1),
>     s1 = new Date;
> session1.match().then(function () {
>     console.log("%d [%dms]", r1.result, new Date - s1);
>     session1.dispose();
> });
>
> var r2 = new Result(),
>     session2 = flow.getSession(new Fibonacci(150), r2),
>     s2 = new Date;
> session2.match().then(function () {
>     console.log("%d [%dms]", r2.result, new Date - s2);
>     session2.dispose();
> });
>
> var r3 = new Result(),
>     session3 = flow.getSession(new Fibonacci(1000), r3),
>     s3 = new Date;
> session3.match().then(function () {
>     console.log("%d [%dms]", r3.result, new Date - s3);
>     session3.dispose();
> });
>
> And of course its on npm
>
> npm install nools
>
> -Doug
>
>

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to