match

match, keyword

match provides pattern matching with compile-time constant cases. Range selectors are allowed for date, number, and text.

Examples

table T = with
  [| as Code |]
  [| "a10" |]
  [| "a11" |]
  [| "a12" |]
  [| "a13" |]

T.Label = match T.Code with
  "a11" -> "Normal teardown"
  "a12" -> "Misuse"
  "a13" -> "Design defect"
  ..    -> "Unqualified scrap"

show table "Codes" with
  T.Code
  T.Label

This produces the following table:

Code Label
a10 Unqualified scrap
a11 Normal teardown
a12 Misuse
a13 Design defect
table T = with
  [| as Value |]
  [| -7 |]
  [| 0 |]
  [| 1 |]
  [| 3 |]
  [| 99 |]

T.Label = match T.Value with
  0       -> "Zero"
  .. 0    -> "Negative"
  1       -> "One"
  2 .. 10 -> "A few"
  ..      -> "Many"

show table "Ranges" with
  T.Value
  T.Label

This produces the following table:

Value Label
-7 Negative
0 Zero
1 One
3 A few
99 Many
User Contributed Notes
0 notes + add a note