dagql/dirty
Convert an immutable NExpr into a mutable DirtyExpr for low-level editing.
// 1. make an app
const app = mvfm(prelude, console_);
// 2. make a program: x + 10
const prog = app({ x: "number" }, ($) =>
$.begin($.console.log("result:", $.add($.input.x, 10)), $.add($.input.x, 10))
);
const injected = injectInput(prog, { x: 5 });
// 3. dagql: dirty opens the NExpr for mutation
const d = dirty(injected.__nexpr);
// swapEntry replaces a single node by ID
const ids = selectWhere(injected.__nexpr, byKind("num/add"));
const addId = [...ids][0];
const entry = d.__adj[addId];
const swapped = swapEntry(d, addId, {
...entry,
kind: "num/sub",
});
// commit seals it back to an immutable NExpr
const result = commit(swapped);
// 4. fold: was 5+10=15, now 5-10=-5
await fold(result, defaults(app)); Ctrl+Enter