Saturday, July 31, 2010

a hypothetical functional language that separates patterns and data from logic and expansion

data multiply-binary-closure = "*"
  -> closure                 = ((a:number \s b:number)
                                  -> multiply = a * b)

data factorial = number "!"
  -> number    = foldl * 1 [1..number]

This is just a simple demonstration, but I think it shows a lot.

Data are created and represented by PEG-like patterns, and have a rule (type) name, and instructions are given on how to explode that data rule into another data rule.

Inside a pattern definition, a rule (like number) is defined as anything that is, or can explode to that rule, directly or indirectly.

closures are just anonymous data patterns invoked with
closure "(" \s? anonymous-pattern-body \s? ")"
for example: closure(1 2) or closure( 3 > 4 )

Edit: just realized that \s is more appropriate than \w for whitespace… (regexp-style)


Notes