Skip to content

Instantly share code, notes, and snippets.

@greymd
Last active March 11, 2016 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greymd/63b1b9623daa7ab1bce7 to your computer and use it in GitHub Desktop.
Save greymd/63b1b9623daa7ab1bce7 to your computer and use it in GitHub Desktop.
「ズン」と「ドコ」をランダムに無限に生成し「ズン・ズン・ズン・ズン・ドコ」のパターンが出現した時に「キ・ヨ・シ♪」と出力して動作を停止するEgisonのコード。
((match-lambda
(list string) {[
<join $a
(loop $i [1 4]
<cons (& ,"ズン" $z_i) ...>
(& <cons ,"ドコ" _> $d))> [a z (car d) "キ・ヨ・シ ♪"]]})
(map 1#(R.car {"ズン" "ドコ"}) nats))
# 結果
# [{"ズン" "ズン" "ドコ" "ドコ" "ドコ" "ズン" "ズン" "ドコ" "ズン" "ズン" "ズン" "ドコ" "ズン" "ズン" "ズン" "ドコ" "ドコ" "ドコ"} {|[1 "ズン"] [2 "ズン"] [3 "ズン"] [4 "ズン"]|} "ドコ" "キ・ヨ・シ ♪"]
@egisatoshi
Copy link

(define $main
  (lambda [$args]
    (each print (kiyoshi (match-all (map 1#(R.car {"ズン" "ドコ"}) nats) (list string)
                           [<join _ (loop $i [1 5] <cons $z_i ...> _)> {z_1 z_2 z_3 z_4 z_5}])))))

(define $kiyoshi
  (match-lambda (list (list string))
    {[<cons (& (loop $i [1 4] <cons ,"ズン" ...> <cons ,"ドコ" <nil>>) $zs) _> {@zs "キ・ヨ・シ ♪"}]
     [<cons <cons $x _> $xs> {x @(kiyoshi xs)}]}))
% egison kiyoshi.egi
ドコ
ズン
ドコ
ドコ
ドコ
ズン
ドコ
ズン
ズン
ドコ
ドコ
ドコ
ドコ
ドコ
ドコ
ドコ
ズン
ズン
ズン
ズン
ズン
ズン
ドコ
キ・ヨ・シ ♪
%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment