tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

patterns.tri (734B)


      1 !import "prelude" !Local
      2 
      3 match_ = y (self value patterns :
      4   triage
      5     t
      6     (_ : t)
      7     (pattern rest :
      8       triage
      9         t
     10         (_ : t)
     11         (test result :
     12           if (test value)
     13              (result value)
     14              (self value rest))
     15         pattern)
     16     patterns)
     17 
     18 match = (value patterns :
     19   match_ value (map (sublist :
     20     pair (head sublist) (head (tail sublist)))
     21     patterns))
     22 
     23 otherwise = const (t t)
     24 
     25 cond_ self patterns =
     26   lazyList
     27     (_ : t)
     28     (pattern rest :
     29       matchPair
     30         (testK actionK :
     31           lazyBool
     32             actionK
     33             (_ : self rest)
     34             (testK t))
     35         pattern)
     36     patterns
     37 
     38 cond patterns = y cond_ patterns
     39 
     40 guard testK actionK = pair testK actionK