diff --git a/scripts/versioning2.js b/scripts/versioning2.js
index 174a615..a825f76 100644
--- a/scripts/versioning2.js
+++ b/scripts/versioning2.js
@@ -16,17 +16,23 @@ const newValue = val => ({
// [inspect.custom]: (depth, options, inspect) => options.stylize(`newValue(${val})`, 'special'),
});
+const id = x => x;
+
// Slot -> Computation
const read = slot => ({
kind: "transformation",
in: slot,
- fn: `${x => x}`,
+ fn: {
+ kind: "value",
+ out: id,
+ },
out: slot.computation.out,
// [inspect.custom]: (depth, options, inspect) => options.stylize(`read(${inspect(slot)})`, 'special'),
});
// Computation -> Computation b> -> Computation
const transform = input => fn => {
+ // console.log("transform...", "input:", pretty(input), "fn:", pretty(fn));
const output = fn.out(input.out);
if (input.kind === "value") {
// our input had no read dependency, thus likewise our output does not:
@@ -36,31 +42,58 @@ const transform = input => fn => {
};
}
else {
+ // console.log("transforming the transformation...");
return {
kind: "transformation",
in: input.in,
- fn,
+ // transform the transformation:
+ fn: transform(input.fn)(newValue(origFn => {
+ const descr = `${fn.out.name} ∘ ${origFn.name}`;
+ return { [descr]: x => fn.out(origFn(x)) }[descr];
+ })),
out: output,
};
}
};
+const counterOne = newSlot(Symbol('counter'))(newValue(1));
+const valueOne = read(counterOne);
-const price = newSlot(Symbol('price'))(newValue(5));
-const tax = newSlot(Symbol('tax'))(newValue(1));
+console.log(pretty({valueOne}));
-const total =
- transform(read(price))(
- transform(read(tax))(
- newValue(tax => price => price + tax)));
+const inc = x => x + 1;
-console.log(pretty({total,}));
+const onePlusOne = transform(valueOne)(newValue(inc));
+
+console.log(pretty({onePlusOne}));
+
+const onePlusOnePlusOne = transform(onePlusOne)(newValue(inc));
+
+console.log(pretty({onePlusOnePlusOne}));
-const getReadDependencies = computation => new Set([
- ...(computation.kind === "value" ? [] : [computation.in, ...getReadDependencies(computation.fn)]),
-]);
+// const price = newSlot(Symbol('price'))(newValue(20.66));
+// const tax = newSlot(Symbol('tax'))(newValue(4.34));
-console.log("getReadDependencies(total):", getReadDependencies(total));
+// console.log(pretty({price}));
+
+// const total =
+// transform(read(price))(
+// transform(read(tax))(
+// newValue(tax => price => price + tax)));
+
+// console.log(pretty({total}))
+
+// const totalPlusOne = transform(total)(newValue(x => x + 1));
+
+// console.log(pretty({totalPlusOne}));
+
+
+
+// const getReadDependencies = computation => new Set([
+// ...(computation.kind === "value" ? [] : [computation.in, ...getReadDependencies(computation.fn)]),
+// ]);
+
+// console.log("getReadDependencies(total):", getReadDependencies(total));