Similar to Python's list comprehension that function in one dimension, Planarly supports table comprehension in two dimensions. The general syntax is as follows:
#[ expression_at_location_R_C if if_condition while while_condition ]
A simple example would be:
#[ R*C while And(R<3, C<2) ]
(alternatively: #[ R*C while R<3 && C<2 ]
)
Which evaluates to:
$$ \begin{array}{|c|c|} \hline 0 & 0 \\ \hline 0 & 1 \\ \hline 0 & 2 \\ \hline \end{array} $$
The if
clause is optional. The while
clause is not needed if a defined table is being used. The above example would generate an error if no while
clause was present. The example below, however, relies on the dimensions of the table #a (or a:Za)
to set the limits of the table comprehension.
R
(case sensitive) denotes the row being evaluated, starting from 0.C
(case sensitive) denotes the column being evaluated, starting from 0.R
does not appear in the table comprehension, then only one row is generated.C
does not appear in the table comprehension, then only one column is generated.if_condition
evaluates to false, then location (R,C)
evaluates to a 0x0 table.while_condition
evaluates to false, then the current row is terminated and we continue with cell R += 1; C = 0;
. If C == 0
when the while_condition
is false, then the table comprehension is done.while_condition
is given, then it defaults to: expression_for_cell
evaluated without any error. An OutOfBounds
error signals a false while_condition
. This error is not propagated to the user, but halts the table comprehension.True
is a non-empty table where every cell contains True
. False
is anything else.The result of every evaluation during a table comprehension is a table. It may be a 1x1 table containing a single value. It may be a 0x0 table if the if_condition
evaluated to false. It may be any larger combination of height and width.
To generate the final table, the tables generated for each location in the table comprehension are placed into a grid. The result is flattened into a single table ensuring there is no overlap between sub-tables.