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.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/2d5c01fe-5927-4425-8326-1ab64a252771/Screenshot_2021-06-04_at_10.52.00.png

Table comprehension syntax details

How a table comprehension is completed

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.