;;; ;;; ;;; Mah-jong example ;;; ;;; ;; ;; Matcher definitions ;; (define $suit (algebraic-data-matcher { })) (define $honor (algebraic-data-matcher { })) (define $tile (algebraic-data-matcher { })) ;; ;; Pattern modularization ;; (define $twin (pattern-function [$pat1 $pat2] >)) (define $shuntsu (pattern-function [$pat1 $pat2] pat1) pat2>>>)) (define $kohtsu (pattern-function [$pat1 $pat2] >>)) ;; ;; A function that determines whether the hand is completed or not. ;; (define $complete? (match-lambda (multiset tile) {[(twin $th_1 (| (shuntsu $sh_1 (| (shuntsu $sh_2 (| (shuntsu $sh_3 (| (shuntsu $sh_4 ) (kohtsu $kh_1 ))) (kohtsu $kh_1 (kohtsu $kh_2 )))) (kohtsu $kh_1 (kohtsu $kh_2 (kohtsu $kh_3 ))))) (kohtsu $kh_1 (kohtsu $kh_2 (kohtsu $kh_3 (kohtsu $kh_4 ))))) (twin $th_2 (twin $th_3 (twin $th_4 (twin $th_5 (twin $th_6 (twin $th_7 ))))))) #t] [_ #f]})) ;; ;; Demonstration code ;; (test (complete? {> > 3> 4> 5> 6> 7> 8> 2> 3> 4> 6> 6> 6>})) (test (complete? {> > 1> 3> 4> 6> 7> 8> 3> 4> 5> 6> 6> 6>}))