This is an old revision of the document!


Records, binds, and the like

Records

A record is an unordered collection of terms, where each term has an associated unique name given by an untyped symbol. The following is an example.

{ name => "Fred", height => %(5,10),
  birthday => { year => 1996, month => 3, day => 21 } }

Note that the terms in a record can be anything, including other records.

Binds

A bind associates variables by name with terms. It looks much like a record, except that it uses variables instead of symbols. The variables cannot have types or guards; this is for performance.

{ $x => 21, $y => ( $z -> 21 ) }

Again, the variables can be associated with any term.

When a binding is applied to a term, free instances of the named variables are replaced with the associated term.

{ $x => 21 } . iadd(17, $x)
--> iadd(17, 21)
--> 38

Again, this works for free variables, only. Lambda variables, which are not free, are not rewritten.

{ $x => 21 } . ( $x -> 17 )
--> $x -> 17

Simple Rules

A simple rule is a sequence of lambda expressions, in order. Note that lambdas use the `→` arrow, where records and binds use the `⇒` arrow.

{ %($x: INTEGER, $y: INTEGER) -> iadd($x,$y),
  %($x: FLOAT, $y: FLOAT) -> fadd($x,$y),
  %($x: STRING, $y: STRING) -> concat($x,$y),
}

When a simple rule is applied to a term, each of the lambdas is tried, in order. The result of the entire apply is the result of the first lambda that succeeds. If no lambda succeeds, the system generates an error. To avoid this case you can use the `ANY` pattern. For instance, if the last lambda is `ANY → ANY` then if no prior lambda matches, the argument is unchanged.

{ %($x: INTEGER, $y: INTEGER) -> iadd($x,$y),
  %($x: FLOAT, $y: FLOAT) -> fadd($x,$y),
  %($x: STRING, $y: STRING) -> concat($x,$y),
} . %("Fred", "Flintstone")
--> "FredFlintstone"