This tutorial covers Planarly features already introduced in Sheet Defined Function and outlined in Table Properties.
In Planarly user functions are defined in a sheet, with each function having its own dedicated sheet. The name of the sheet is used to call the function.
Related functions are often created under a parent sheet, eg Stats.t_test, to create reusable, modular libraries.
For this tutorial we are going to create a simple function that does a cellwise squaring (x * x) of whatever is passed in.
The first step is to create a sheet, square
where this function will be defined.
The function is very simple. At the top we define the space for the single function parameter, which is the smallest 2-dimensional table able to be defined by X0
and ZX0
. Like the Z
prefix marks a bottom right table corner, the X
prefix marks a function parameter. For more details see the Sheet Defined Functions tutorial. Note that the table #X0
is only 2 rows by 2 columns.
The return value of the function is a formula in a cell labelled Return
. Here, Planarly's cell-wise multiplication makes squaring a table of any dimensions a single operation.
The square()
function is called from sheet1
here by the relative path to the square
sheet from its shared parent (P
) with sheet1
. The result is the cell-wise square of the values in #a
. We could have also used Root.square(#a)
.
square()
also works for single cell values, but note that the function call still uses #a
to pass a
in as a reference to a 1x1 table instead of as a single value.