CalcAnyway · Card reference · updated 2026-10-23

My functions — name a calculation and call it again and again

My functions let you give a name to a calculation you have already built and call it as many times as you like. In Board 1, the calculation "price before tax × (1 + tax rate ÷ 100)" is turned into a function called price_with_tax and called twice. For detergent (300 yen before tax, 10% tax) the price with tax is 330 yen; for water (100 yen, 8%) it is 108 yen; the two together come to 438 yen. Three cards are involved: the function call, the function output and the function result list.

Board 1

Open in CalcAnyway ↗

You can change the numbers here too, but changes made in this frame are not saved. To keep them, open it in CalcAnyway and edit there.

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.

Board 2

Open in CalcAnyway ↗

You can change the numbers here too, but changes made in this frame are not saved. To keep them, open it in CalcAnyway and edit there.

Function result list

When a list column is connected to a slot, that slot becomes one value per row, and the call runs once per row. Board 2 connects two lists, "Prices before tax" and "Tax rate", to the two slots of a call named Basket. There are four rows: Bento, Beer, Water and Detergent.

"Basket result" is the list of results by row. Bento is 540 yen, Beer 220 yen, Water 108 yen and Detergent 330 yen, and the total is 1,198 yen. That is the same 1,198 yen as in Board 1 of the consumption tax article (in Japanese). The menu under the list chooses how to summarise (sum, average and so on), and the list can feed charts and histograms.

The two lists have the same row names, so rows are matched by name; reordering the tax-rate list still matches the same items. When the names do not match, rows are paired from the top and a "Row names do not match" notice appears. When the lists differ in length, only the shorter length is calculated; with three rows in the tax-rate list (Bento, Beer, Water), three rows are calculated and the total is 868 yen.

Registered functions

Choosing "Register in the app" from the ⋯ menu of a function's output card keeps a copy of the body in this browser. From "Registered functions" on the "My functions" shelf, or "Registered functions…" in the ☰ menu, you can place the body and a call together on any other board. Registered functions can be updated and deleted, and exported to or imported from a file (to move them to another device). They exist only in that device's browser.

Limits

  • Functions called inside functions can be nested up to 8 levels. A function cannot call itself.
  • A single calculation can make up to 20,000 function calls.
  • A function can have up to 32 arguments.
  • "View with these values" is not offered in view and answer modes, and does not work on a call with a list column connected.

Articles that use these cards

  • Deviation score (in Japanese) — turns the deviation-score calculation into a function, connects a list of 30 scores, and gets everyone's score and their average.

Read next — Basics Calculation, input, list and the other cards that most boards are built on.


Back to the card reference →