# Rename a source binding using the compiler's scope analysis. original_source = "unit_price = 7\nquantity = 6\n# Preserve this explanation.\ntotal = unit_price * quantity\n" edit = AST.RENAME(original_source, 1, "price_per_item") updated_source = edit.updatedSource compilation_report = AST.CHECK(updated_source) # Expression substitution has lexical scope and avoids variable capture. template = AST.QUOTE((quantity) => amount + quantity) substituted = AST.SUBSTITUTE(template, { amount: AST.QUOTE(quantity) }) substituted_source = AST.RENDER(substituted) # Module substitution protects generated names as well as local parameters. module_template = AST.MODULE([ AST.ASSIGN("answer", AST.CALL("calculate", [AST.REFERENCE("input")])), AST.FUNCTION("calculate", ["amount"], AST.QUOTE(amount + offset)), AST.ASSIGN("offset", AST.LITERAL(7)) ]) module_rewritten = AST.SUBSTITUTE(module_template, { input: AST.QUOTE(offset) }) module_source = AST.RENDER(module_rewritten) # Inspect and update independent occurrences in one bounded batch. formula = AST.QUOTE(unit_price * quantity + delivery_fee) references = AST.SELECT(formula, { kinds: ["Atom"] }) operation_support = AST.CAPABILITIES(formula, []) revised = AST.REWRITE(formula, [ { path: [0, 0], replacement: AST.LITERAL(7) }, { path: [1], replacement: AST.LITERAL(5) } ]) batch_source = AST.RENDER(revised) # Preview and apply a complete revision-bound signature change as source data. callable_source = "price(quantity) = quantity * 7\nanswer = price(6)" parsed_callable = AST.PARSE(callable_source) transaction = AST.EDIT(callable_source, { revision: parsed_callable.sourceRevision, operation: { kind: "changeSignature", function: "price", parameters: [{ name: "items", from: "quantity" }] } }) transaction_source = AST.APPLY(callable_source, transaction)