function calls

Function calls use a name followed by parentheses. Some calls also supply arguments between << and >>, before the parentheses: table arguments for vector functions, or the target enumeration for enum, as in enum<<E>>("value"). Most functions take positional arguments, some are variadic, and a few require labeled arguments.

Positional and variadic arguments

x = abs(-42)
y = max(1, 3, 42, 12)

show summary "" with x, y

Variadic functions accept a variable number of positional arguments.

Table arguments for vector functions

A def vector call supplies tables in declaration order between << and >>, and column expressions inside the parentheses. For the summarize function defined on the def page, the call is:

Products.TotalQty, Products.TotalAmount =
  summarize<<Products, Sales>>(Sales.Qty, Sales.Price)

Here, Products binds the table parameter P, and Sales binds S. The supplied tables must have the relationships declared by the function’s expect table statements. Column arguments bind by position, not by their names in the calling script.

The same table-argument syntax applies to imported vector functions. With a module alias, the function name is qualified, as in the module example:

Products.Total = Metrics.totalQty<<Products, Sales>>(Sales.Qty)

When the function name is imported directly through a with block, omit the module alias and use totalQty<<Products, Sales>>(Sales.Qty).

Labeled arguments

Some built-in functions require labeled arguments. Labeled arguments are newline-separated and cannot be mixed with positional arguments. User-defined functions only support positional arguments.

table Items[Id] = with
  [| as Id |]
  [| "kit" |]
  [| "partA" |]

table BOM = with
  [| as RawId, as PartId, as Quantity |]
  [| "kit", "partA", 2 |]

expect BOM.Id = BOM.RawId

table Orders = with
  [| as Uid, as Quantity |]
  [| "kit", 3 |]

expect Orders.Id = Orders.Uid

table T = extend.billOfMaterials(
  Item: Items.Id,
  Part: BOM.PartId,
  Quantity: BOM.Quantity,
  DemandId: Orders.Uid,
  DemandValue: Orders.Quantity)

show table "" with
  Items.Id
  T.DemandId
  T.Quantity

Namespaced function names

Some built-in functions include a dot in their name for namespacing, for example lastForex. The dot is purely a naming convention and has no special semantics.

See also