MVFM

dagql/name

Create named aliases for nodes — enables targeting by name instead of ID.

// 1. make an app
const app = mvfm(prelude, console_);

// 2. make a program: (x + 10) * 2
const prog = app({ x: "number" }, ($) =>
  $.begin(
    $.console.log("result:", $.mul($.add($.input.x, 10), 2)),
    $.mul($.add($.input.x, 10), 2)
  )
);

const injected = injectInput(prog, { x: 5 });

// 3. dagql: name the add node, then target it by name
const addIds = selectWhere(injected.__nexpr, byKind("num/add"));
const addId = [...addIds][0];
const named = name(injected.__nexpr, "the-sum", addId);

// byName finds the target of the alias
const found = selectWhere(named, byName("the-sum"));
console.log("found by name:", found.size, "node(s)");

// replace by name instead of by kind
const rewritten = commit(
  replaceWhere(named, byName("the-sum"), "num/sub")
);

// 4. fold: was (5+10)*2=30, now (5-10)*2=-10
await fold(rewritten, defaults(app));
Ctrl+Enter