default

The default keyword is used in Envision to define edge-case behaviors of processes or operators.

expr1[expr2] default expr3, lookup behavior on missing key

The default option can be applied to lookup to override the behavior of the loopup if the key is not found in the probed table.

table Products[product] = with
  [| as product,   as Price |]
  [| "apple",      1.50     |]
  [| "pear",       1.30     |]
  [| "orange",     2.10     |]
  [| "clementine", 2.70     |]
 
missingPrice = Products.Price["banana"] default -1 // 'banana' does not belong to 'product'

show scalar "" with missingPrice // -1

‘proc(expr1) default expr2’, process behavior on empty grouping

When calling a process, the most typical processes in Envision being aggregators, the option default can optionally be specified to define the behavior of the process over empty grouping.

table T = with
  [| as N |]
  [| 1    |]
  [| 2    |]
  [| 3    |]

where T.N < 0 // no lines left in 'T'
  // 'sum(T)' is aggregated to the 'Scalar' table
  show scalar "sum" with sum(T.N) default -1 // -1, because of 'default'

When default is not provided, aggregations return the data type default:

The default option is aligned with the group table, and can be a vector.

table Orders = with
  [| as Product, as Qty |]
  [| "apple", 3 |]
  [| "orange", 2 |]

table Products = with
  [| as Product, as Fallback |]
  [| "apple", 0 |]
  [| "orange", 0 |]
  [| "banana", -1 |]

Products.Sold = sum(Orders.Qty)
  by Orders.Product
  at Products.Product
  default Products.Fallback

show table "Sold" with
  Products.Product
  Products.Sold

‘def process funname(args) default expr with’, user-defined process

When introducing a user-defined process, the value to be returned over empty groupings can optionally be specified via the default option.

table T = with
  [| as N |]
  [| 1    |]
  [| 2    |]
  [| 3    |]

def process mySum(x : number) default -1 with // -1 on empty grouping
  keep sum = 0 // state of the process
  sum = sum + x
  return x

where T.N < 0 // no lines left in 'T'
  // 'sort' is mandatory, but here, ordering matters not.
  show scalar "sum" with mySum(T.N) sort 1 // -1 (due to 'mySum' definition)

See also

User Contributed Notes
0 notes + add a note