36 lines
1.1 KiB
Plaintext
36 lines
1.1 KiB
Plaintext
|
!import "list.tri" !Local
|
||
|
|
||
|
match_ = y (\self value patterns :
|
||
|
triage
|
||
|
t
|
||
|
(\_ : t)
|
||
|
(\pattern rest :
|
||
|
triage
|
||
|
t
|
||
|
(\_ : t)
|
||
|
(\test result :
|
||
|
if (test value)
|
||
|
(result value)
|
||
|
(self value rest))
|
||
|
pattern)
|
||
|
patterns)
|
||
|
|
||
|
match = (\value patterns :
|
||
|
match_ value (map (\sublist :
|
||
|
pair (head sublist) (head (tail sublist)))
|
||
|
patterns))
|
||
|
|
||
|
otherwise = const (t t)
|
||
|
|
||
|
-- matchExample = (\x : match x [[(equal? 1) (\_ : "one")]
|
||
|
-- [(equal? 2) (\_ : "two")]
|
||
|
-- [(equal? 3) (\_ : "three")]
|
||
|
-- [(equal? 4) (\_ : "four")]
|
||
|
-- [(equal? 5) (\_ : "five")]
|
||
|
-- [(equal? 6) (\_ : "six")]
|
||
|
-- [(equal? 7) (\_ : "seven")]
|
||
|
-- [(equal? 8) (\_ : "eight")]
|
||
|
-- [(equal? 9) (\_ : "nine")]
|
||
|
-- [(equal? 10) (\_ : "ten")]
|
||
|
-- [ otherwise (\_ : "I ran out of fingers!")]])
|