156 lines
5 KiB
JavaScript
156 lines
5 KiB
JavaScript
import { newDynamic } from "../lib/primitives/dynamic.js";
|
|
import { Char, Int } from "../lib/primitives/primitive_types.js";
|
|
import { fnType } from "../lib/structures/type_constructors.types.js";
|
|
import { pretty } from "../lib/util/pretty.js";
|
|
import { newLiteral, newSlot, read, transform, write } from "../lib/versioning/static/value_slot.js";
|
|
import { merge, mergeN } from "../lib/versioning/static/merge.js";
|
|
import { union } from "../lib/structures/set.js";
|
|
import { emptyDict, set } from "../lib/structures/dict.js";
|
|
import { compareInts, compareStrings } from "../lib/compare/primitives.js";
|
|
import { compareDicts } from "../lib/compare/structures.js";
|
|
|
|
const inc = x => x + 1n;
|
|
const incLiteral = newLiteral(newDynamic(inc)(fnType(_=>Int)(_=>Int)));
|
|
|
|
|
|
// {
|
|
// console.log("##############");
|
|
// console.log("## Counting ##");
|
|
// console.log("##############");
|
|
|
|
// const counterOneSlot = write
|
|
// (newSlot("1d61577e704613f4e48b164852aedd20"))
|
|
// (newLiteral(newDynamic(1n)(Int)));
|
|
|
|
// console.log(pretty({counterOneSlot}));
|
|
|
|
// const valueOne = read(counterOneSlot);
|
|
|
|
// console.log(pretty({valueOne}));
|
|
|
|
// const onePlusOne = transform
|
|
// (valueOne)
|
|
// (incLiteral);
|
|
|
|
// console.log(pretty({onePlusOne}));
|
|
|
|
// const onePlusOnePlusOne = transform
|
|
// (onePlusOne)
|
|
// (incLiteral);
|
|
|
|
// console.log(pretty({onePlusOnePlusOne}));
|
|
// }
|
|
|
|
// // console.log("#############");
|
|
// // console.log("## Summing ##");
|
|
// // console.log("#############");
|
|
|
|
// // const priceSlot = newSlot(Symbol('price'))(newLiteral(20.66));
|
|
// // const taxSlot = newSlot(Symbol('tax'))(newLiteral(4.34));
|
|
|
|
// // const total =
|
|
// // transform(read(priceSlot))(
|
|
// // transform(read(taxSlot))(
|
|
// // newLiteral(tax => price => price + tax)));
|
|
|
|
// // console.log(pretty({total}))
|
|
|
|
// // const totalPlusOne = transform(total)(newLiteral(inc));
|
|
|
|
// // console.log(pretty({totalPlusOne}));
|
|
|
|
// // verifyValue(totalPlusOne);
|
|
|
|
// // console.log("getReadDependencies(totalPlusOne):", getReadDependencies(totalPlusOne));
|
|
|
|
|
|
// {
|
|
// console.log("###############");
|
|
// console.log("## Branching ##");
|
|
// console.log("###############");
|
|
|
|
// const initialSlot = newSlot("Slot__4a029b3d758bcd1fffbf495531c95537");
|
|
|
|
// const slotA = write(initialSlot)(newLiteral(newDynamic("a")(Char)));
|
|
// const slotB = write(slotA )(newLiteral(newDynamic("b")(Char)));
|
|
// const slotC = write(initialSlot)(newLiteral(newDynamic("c")(Char)));
|
|
|
|
// const slotAB = merge(slotA)(slotB);
|
|
// const slotAC = merge(slotA)(slotC);
|
|
// const slotBC = merge(slotB)(slotC);
|
|
|
|
// console.log({slotAB, slotAC, slotBC});
|
|
|
|
// const un = union(slotAC)(slotBC);
|
|
|
|
// const merged = mergeN(un);
|
|
|
|
// console.log("merged:", merged);
|
|
// }
|
|
|
|
{
|
|
console.log("#################");
|
|
console.log("## Dict insert ##");
|
|
console.log("#################");
|
|
|
|
const dictSlot = write
|
|
(newSlot("MyDictSlot__d2e87499d9cf46b5c86d420c2057f52f"))
|
|
(newLiteral(emptyDict(compareStrings)));
|
|
|
|
const insertedX = write(dictSlot)
|
|
(transform
|
|
(read(dictSlot)) // input
|
|
(transform // fn (set "x" => 1n)
|
|
(newLiteral(1n))
|
|
(transform
|
|
(newLiteral("x"))
|
|
(newLiteral(set))
|
|
)));
|
|
const insertedY = write(dictSlot)
|
|
(transform
|
|
(read(dictSlot)) // input
|
|
(transform // fn (set "y" => 2n)
|
|
(newLiteral(2n))
|
|
(transform
|
|
(newLiteral("y"))
|
|
(newLiteral(set))
|
|
)));
|
|
|
|
const merged = merge
|
|
(compareDicts(compareStrings)(compareInts))
|
|
(insertedX)
|
|
(insertedY);
|
|
|
|
// is a conflict, but shouldn't be one...
|
|
// can we add the 'domain knowledge' that the composition of two non-key-overlapping dict.set-operations is commutative?
|
|
console.log({merged});
|
|
}
|
|
|
|
// // console.log(compareSlots(intCompare)(fiveSlot)(fiveSlot));
|
|
// // console.log(compareSlots(intCompare)(sixSlot)(sixSlot));
|
|
// // console.log(compareSlots(intCompare)(fiveSlot)(sixSlot));
|
|
// // console.log(compareSlots(intCompare)(sixSlot)(fiveSlot));
|
|
|
|
|
|
// console.log(pretty({sixSevenEightSlot}));
|
|
|
|
// // console.log("########################");
|
|
// // console.log("## Heterogeneous data ##");
|
|
// // console.log("########################");
|
|
// // // Slot<Int>
|
|
// // const numberOfSheepSlot = newSlot(Symbol('numberOfSheep'))(newLiteral(5));
|
|
// // const alternativeNumberOfSheepSlot = newSlot(Symbol('alternativeNumberOfSheep'))(newLiteral(6));
|
|
// // // Slot<String>
|
|
// // const labelSlot = newSlot(Symbol('label'))(newLiteral("number of sheep"));
|
|
// // const combineFn = newLiteral(label => numberOfSheep => `${label}: ${numberOfSheep}`)
|
|
// // // Slot<String>
|
|
// // const labelAndValueSlotA = overwrite(labelSlot)(
|
|
// // transform(read(numberOfSheepSlot))(
|
|
// // transform(read(labelSlot))(combineFn)));
|
|
// // const labelAndValueSlotB = overwrite(labelSlot)(
|
|
// // transform(read(alternativeNumberOfSheepSlot))(
|
|
// // transform(read(labelSlot))(combineFn)));
|
|
// // console.log(
|
|
// // add(add(emptySet(compareSlots(compareStrings)))(labelAndValueSlotA))(labelAndValueSlotB)
|
|
// // );
|
|
// // merge()(labelSlot)(labelAndValueSlot)
|