Skip to content

Instantly share code, notes, and snippets.

@xenophobia
Created July 27, 2014 19:05
Show Gist options
  • Save xenophobia/254e0b0cce84cdfbf9b0 to your computer and use it in GitHub Desktop.
Save xenophobia/254e0b0cce84cdfbf9b0 to your computer and use it in GitHub Desktop.
;; 従来のcard matcherをregular-card matcherにリネーム
(define $regular-card
(algebraic-data-matcher
{<card suit (mod 13)>}))
;; Joker入りcard matcher
;; (,<Joker>みたいなvalue typeは考えてない
;; 欲しけりゃプリミティブパターン節を一個追加すればいいと思うけど未検証)
(define $card
(matcher
{[<card $ $> [suit (mod 13)]
{[<Card $x $y> {[x y]}]
[<Joker> (concat (map (lambda [$x] (map (lambda [$y] [y x]) {<Spade> <Heart> <Club> <Diamond>})) (between 1 13)))]}]
;; Jokerは52種どんなカードとしてもマッチする。
[$ [regular-card] {[$tgt {tgt}]}]}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment