<t-call>

A function call whose arguments the reader can change: savings(deposit=200, rate=0.05, …). The numbers drag, the choices cycle and the text is editable. Give it a name, and the call's return value becomes a variable you can show anywhere.

200 0.05 10 month

Putting away a month at for years returns .

The arguments are ordinary <t-num>, <t-choice>, <t-select> and <t-text> elements, so they work exactly as they do in prose. They are also ordinary variables: the deposit in the sentence is the same one as in the call, and hovering either highlights both. <t-call> adds the function name, a name= before each argument and the punctuation in between. String values get quotes. To show an HTML element instead of a function call, use <t-tag>.

Attributes

AttributeDefaultDescription
fnThe function to call, by its registered name. Any expression that gives a function works, such as Math.hypot. It's also the name shown before the parentheses.
nameThe variable that holds the call's return value, like <t-let>. Without it, the call only displays its arguments.
displayShows the call as a block with a border, instead of inline code.

The arguments are the children that have a name, in order. The function receives their values positionally: savings(deposit, rate, years, every).

Inline

Without display, the call sits in the text like inline code:

The hypotenuse is 34 = .

From a JavaScript function

tangleCall(fn, options) builds a <t-call> from a function's parameters, the way a signature reads. Each default sets the starting value and the kind of argument:

DefaultArgument
A numberA draggable <t-num>. The step is 1 for whole numbers, and otherwise matches the default's decimals: 0.05 steps by 0.01.
true or falseA <t-choice> toggle between true and false.
A stringAn editable <t-text>, or a choice if you give options: a <t-select> with select: true.

Add the returned element to the page. It joins the scope it lands in:

Your order: .

The options are:

OptionDescription
nameThe variable that holds the return value, like the name attribute.
paramsSettings per parameter: min, max, step, format, color, label and pixelsPerStep work as the attributes of the same name. options (a list of values, or { label, value } objects) turns the argument into a choice, select: true makes that choice a <t-select> menu, and value replaces the default.

The returned element has no display attribute. Set it before adding the element to get the block style: el.setAttribute("display", "").

tangleCall reads the parameters from the function's source, so a few things don't work:

parseParams(fn) is the part that reads the source. It returns [{ name, value, hasDefault }], in case you want to build something else from a signature.

Layout

The call stays on one line while it fits. When it's too wide for its container, it wraps the way Python's Black formatter does, with one argument per line and a trailing comma:

savings(
    deposit=200,
    rate=0.05,
    years=10,
    every='month',
)

It switches back as soon as it fits again.