Columnal Documentation: Table of Contents

Syntax

If Then ElseMatchDefineFunctionImplicit Function
@if condition @then value if true @else value if false @endif For any types t @if Boolean @then t @else t @endif

Chooses between two expressions depending on whether the condition is true or false. For example, @if score >= 0 @then "Positive" @else "Negative" @endif would check whether the score expression is greater than or equal to zero. If it was, the result would be the "Positive" text; otherwise it would be the "Negative" text.

ExamplesClick an example to insert it
@if 5 >= 0 @then "Positive" @else "Negative" @endif"Positive"
@if "A" = "B" @then 1 @else 0 @endif0
@match expression @case pattern @given guard @orcase another pattern @given another guard @then value if matches @endmatch For any types c, t @match c @case c @given Boolean @orcase c @given Boolean @then t @endmatch

Matches against several possible alternatives. For example, @match desc @case "full" @orcase "max" @then 1.0 @case _ @then 0.5 @endmatch checks if desc is equal to "full" or "max". If so, the result is 1.0, otherwise (the case underscore matches anything else) the result is 0.5.

ExamplesClick an example to insert it
@match "B" @case "A" @then true @case "B" @then false @endmatchfalse
@match "Hello There" @case "Bye" @then "Leaving" @case "Hello" ; _ @then "Arriving" @endmatch"Arriving"
@match 32 @case 0 @then "Zero" @case n @given n > 0 @then "Positive" @endmatch"Positive"
@define definition @then expression @enddefine @define _ @then t @enddefine

Defines a name for a value, to allow later use. Often you may find yourself repeating the same piece of code, which is both tiresome to enter, and awkward when you need to edit it in multiple places later. By defining a name for the shared code, it's easier to reference and edit.

Another use for definitions is to do pattern matching, especially for things like optional types; for example @define Is(x) = Column with optional type @then x @enddefine

ExamplesClick an example to insert it
@define feet mm = convert unit(unit{mm},1{foot}) @then (6 * feet mm) * (4 * feet mm) @enddefine2229672.96{mm^2}
@define sq = @function(x) @then x*x @endfunction, x = sq(256) @then x - 1 @enddefine65535
@define distance :: type{Number{m}}, distance = from text("23") @then distance * 2 @enddefine46{m}
@function parameters @then body @endfunction @function a @then b @endfunction

Makes a function. The comma-separated list of parameters goes after the function\\keyword, and the body of the function goes after the @then. Functions are very often used with @define, which allows you to name and re-use the function.

If the function you need is very simple and uses its parameter once, you may find the quest syntax useful.

ExamplesClick an example to insert it
@define low = @function(a, b) @then @if a < b @then a @else b @endif @endfunction @then low(3, -5) @enddefine-5
apply each([2,3,4], @function(x) @then x * x @endfunction)[4,9,16]
? ?

Sometimes you want a function that does something very simple, like adding one to a number. The full function syntax is cumbersome for this. Instead you can write (? + 1), which is a function with a single parameter that adds one to get the result. If you have multiple question marks, e.g. ? * ?, the function has as many parameters as there are question marks.

The function extends to the single expression that the question mark(s) appear in. So 0 <= ? < ? <= 1 takes two parameters and checks that the first is less than the second, and they are both between zero and one. The expression (? + 1) * 2 is a type error because you can't multiply a function like two (use the full function syntax instead).

ExamplesClick an example to insert it
apply each([3,7,-4], (? + 1))[4,8,-3]
combine([2, 4, 3], (? * ?))24
group count

A count of the number of items that collapsed into the destination row. The aggregate expression can either be calculated once for the whole source table (in which case this variable is the length of the source table) or split by row values.

For example, if you split by a boolean column Winning, there will be one aggregated row for all the rows in the source table where Winning was true -- and there, group count will be the number of rows in the source table where Winning was true.

If you want a frequency table, using group count by itself will produce the right result.

row

The number of the current row. The first row is 1, the second row is 2 and so on.