The two cards on the left are inputs: price before tax 500 and tax rate 8. The calc card next to them, price_with_tax, uses the same formula and shows the sample value, 540 yen. The "ƒ price_with_tax(Price before tax, Tax rate)" in its title marks this calculation as a function. tax_amount is another calc card that uses the same inputs; it shows 40 yen.
Detergent and Water on the right are calls, where you type the arguments. Detergent is 300 before tax at 10%, which gives 330 yen; Water is 100 at 8%, which gives 108 yen. The small card under each call is that call's second output, the tax: 30 yen and 8 yen. The summary card at the far right adds the two calls: 438 yen.
Make a function
Choose "Make a function" from the ⋯ menu of a calc card. In the dialog, set the function's name, its arguments and its outputs, then press OK. Cards do not move and none are added; the output card just gets an ƒ mark and the name.
The body is found by following the formulas upstream from the card you chose. Calc cards are the inside of the body, and input cards are the arguments. Any other card (a list total, a unit conversion and so on) counts as something outside the body, and its current value is read. In Board 1 the inputs for price before tax and tax rate become the arguments. The arguments are ordered as they appear in the formula; the ↑↓ buttons in the dialog reorder them, and "Fix" takes an input card out of the arguments.
A function needs at least one input card as an argument. A name starts with a letter or _, contains only letters, digits and _, and is at most 20 characters. A name cannot be used twice on one board, and cannot clash with built-in function names such as sin or max.
There is only one body, and every call refers to it, so changing the body's formula changes all the calls. In Board 1, adding "+ 10" at the end of the formula in price_with_tax makes the body 550 yen, Detergent 340 yen and Water 118 yen, and the total 458 yen.
Function call
When a board has a function, a "My functions" shelf appears in the palette; placing from it creates a call card. The call has one slot per argument: type a number or draw a line from another card. A line turns the slot into a reference, and removing the line brings the field back. The value is the body's first output, and the unit and number of decimals come from the body's output card.
An empty slot leaves the call unanswered and its value shows "—"; it is never silently 0. In Board 1, emptying the tax-rate slot of Detergent makes Detergent "—" and the connected total "—", while Water stays at 108 yen.
"View with these values" on a call card temporarily puts that call's arguments into the body's inputs, so you can read the steps with its numbers. For Detergent, the body gets 300 and 10, and shows 330 yen with tax of 30 yen. This view is not saved. "Go to definition" jumps to the body.
If the function is removed ("Stop being a function") or its body deleted, the call shows ⚠ and "Function not found".
A function can also be called from a calc card's formula, but only if its name uses letters and digits. Name the function in Board 1 withTax and write withTax(300, 10) + withTax(100, 8) in a calc card, and it gives 438. A function with a Japanese name is used through call cards.
Function output
A function can have several outputs. In the "Make a function" or "Edit function" dialog, choose other calc cards that use the same inputs as the second and later outputs, and small output cards line up under the call. They move and disappear with the call, and all change together when you change an argument. Draw lines from them to use them as X and Y of a scatter chart, in calc cards and in summaries.
In Board 1, tax_amount is the second output: 30 yen under Detergent and 8 yen under Water.
Bring this function into your own board
The price_with_tax function in Board 1 (the body, the tax output, the Detergent call and the tax card under it) can be copied with the button below. On a CalcAnyway board, press Ctrl+V (⌘+V on a Mac) on an empty spot to paste it as cards. Click an empty spot first; while a card's text is being edited, the paste goes into that text instead. The link between the body and the call stays intact after pasting. If the board already has a function with the same name, the pasted function's name gets a 2.
The button sends nothing outside the page; it only writes to your clipboard.