Defs
A Def names a computation. Reading it computes a Bag from data, without changing any data.
Name a computation
Section titled “Name a computation”def declares a Def. Other Defs can use its name:
def colors = {"red", "blue", "blue"}def color_names = colors%color_names // {"blue", "red"}Name steps with let
Section titled “Name steps with let”Inside braces, let names an intermediate result. The name is available after its let, and it cannot change:
def built = { let first! f64 = 1 let second! f64 = first + 1 {first, second}}built // {1, 2}The braces collect their expressions into one result Bag. A let names a result without adding it to that Bag.
A binder can name the parts of a result: let [x, y] = point selects its Tuple positions, and let (name: label) = item selects a Record field. Add a whole name with @ to keep both:
def described_point = { let point @ [x, y] = [3, 4] (point: point, squared: x * x + y * y)}described_point // {(point: [3, 4], squared: 25)}The same binder works in a kernel header: rows map row @ (name: label) => [row, label] names each whole row and its name field.
SakaQL works out each Def’s Set and cardinality from its expression. You can also state a contract, and the result must fit it.