Skip to content

Instantly share code, notes, and snippets.

@ehlyzov
Created July 17, 2016 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehlyzov/387133a63bd7c5abcf6dbe1f2a30e0fe to your computer and use it in GitHub Desktop.
Save ehlyzov/387133a63bd7c5abcf6dbe1f2a30e0fe to your computer and use it in GitHub Desktop.
FizzBuzz based on nools.js
'use strict';
const nl = require('nools');
class Message {
constructor() {
this.text = '';
}
set append(text) {
this.text = this.text + text;
}
get value() {
return this.text;
}
}
let flow;
let session;
nl.deleteFlow('FizzBuzz');
flow = nl.flow("FizzBuzz", function(flow) {
flow.rule("FizzBuzz", {salience: 3}, [
[Number, 'num', "num % 15 == 0"]
], function (facts) {
console.log(facts.num, 'FizzBuzz');
this.retract(facts.num);
});
flow.rule("Fizz", {salience: 1}, [
[Number, 'num', "num % 3 == 0"],
], function (facts) {
console.log(facts.num, 'Fizz');
this.retract(facts.num);
})
flow.rule("Buzz", {salience: 2}, [
[Number, 'num', "num % 5 == 0"],
], function (facts) {
console.log(facts.num, 'Buzz');
this.retract(facts.num);
})
});
session = flow.getSession();
for (let i = 1; i<100; i++) {
session.assert(i);
}
session.match().then(
function(){
console.log("Done");
},
function(err){
//uh oh an error occurred
console.error(err.stack);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment