5.5. Record Pattern

When a record pattern is matched against a record value, each key mentioned in the record pattern must have a mapping in the record value, and each such mapped value must match its corresponding pattern. The record value may contain additional keys not mentioned by the record pattern.

5.5.1. Syntax

[41]RecordPattern::= {. Key = Pattern , , Key = Pattern .}  

5.5.2. Type

When a record pattern {. K0 = P0 ,, Kn = Pn .} is matched against a record type R, each Ki must have a binding in R. Then each Pi is matched against the type bound to Ki in R, producing a typing context Γi. The typing context produced by the whole match is the union of the contexts Γi.

5.5.3. Examples

Student Applications
{- Use records to test for a given string -}

val applicants = 
[
  {. name = "Harry Q. Bovik", college = "Carnegie Mellon University", status = "accepted" .},
  {. name = "Fred Hacker", college = "Massachusetts Institute of Technology", status = "rejected" .},
  {. name = "D. F. Automaton", college = "Final State College", status = "accepted" .}
]
each(applicants) >a>
(
    a >{. name = n, status = "accepted" .}> Println(n + "'s application was accepted") >> stop
  | a >{. name = n, status = "rejected" .}> Println(n + "'s application was not accepted") >> stop
)

{-
OUTPUT:PERMUTABLE
Fred Hacker's application was not accepted
D. F. Automaton's application was accepted
Harry Q. Bovik's application was accepted
-}

5.5.4. Related Links

Related Reference Topics

Related Tutorial Sections