Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ConorOBrien-Foxx committed Sep 3, 2016
1 parent 5a29f88 commit dab7c07
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/stdlib/ns/modular.es6
@@ -0,0 +1,10 @@
// modular library written by Conor O'Bruie

export default function(cheddar){
// let modular = new cheddar.func();
// modular.scope = new Map([

return cheddar.namespace([
["of", cheddar.from(require("./modular/of"))]
]);
}
35 changes: 35 additions & 0 deletions src/stdlib/ns/modular/helpers/ModularClass.es6
@@ -0,0 +1,35 @@
let importInstance;
export default function(cheddar){
console.log("from ModularClass.es6")
console.log(cheddar);
if(importInstance) return importInstance;

return importInstance = class ModularSystem extends cheddar.class {
init(min, max){
this.setter("min", min);
this.accessor("min");
this.setter("max", max);
this.accessor("max");
}

// MUST be capitalized, otherwise bork
Scope = new Map([
["fit", cheddar.var(
new cheddar.func([
["entry", { type: cheddar.number }]
], function(scope, input){
let self = input("self"),
value = input("entry"),
min = self.accessor("min"),
max = self.accessor("max");

while(value < this.min) value += this.max;
while(value >= this.max) value -= this.max;
return value;
})
)]
]);
}

return ModularSystem;
};
16 changes: 16 additions & 0 deletions src/stdlib/ns/modular/of.es6
@@ -0,0 +1,16 @@
import Modular from "./helpers/ModularClass";

export default function(cheddar){
return new cheddar.func(
[
["min", { type: cheddar.number }],
["max", { type: cheddar.number }]
],
function(cheddar, input){
return new (Modular(cheddar))(
input("min"),
input("max")
);
}
);
}
1 change: 1 addition & 0 deletions src/stdlib/stdlib.es6
Expand Up @@ -18,6 +18,7 @@ STDLIB.Item("cheddar");

STDLIB.Item("Math");
STDLIB.Item("Rational");
STDLIB.Item("modular");

// Interface Libraries
STDLIB.Item("Encoding");
Expand Down

0 comments on commit dab7c07

Please sign in to comment.