This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define $Multiset | |
(lambda [$a] | |
(type | |
{[,$val [] | |
{[$tgt (match [val tgt] [(Multiset a) (Multiset a)] | |
{[[<nil> <nil>] {[]}] | |
[[<cons $x $xs> <cons ,x ,xs>] {[]}] | |
[[_ _] {}]})]}] | |
[<nil> [] | |
{[{} {[]}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define $poker-hands | |
(lambda [$Cs] | |
(match Cs (Multiset Card) | |
{[<cons <card $S $n> | |
<cons <card ,S ,(- n 1)> | |
<cons <card ,S ,(- n 2)> | |
<cons <card ,S ,(- n 3)> | |
<cons <card ,S ,(- n 4)> | |
!<nil>>>>>> | |
<straight-flush>] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% cd sample/icfpc2012/ | |
% egisonc mine.egi | |
[1 of 1] Compiling Main ( _tmp.hs, _tmp.o ) | |
Linking mine ... | |
% ./mine maps/contest1.map | |
###### | |
#. *R# | |
# \.# | |
#\ * # | |
L .\# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> (test (match-all {0 1} (Set Integer) | |
[<cons $a_1 <cons $a_2 <cons $a_3 _>>> | |
{a_1 a_2 a_3}])) | |
{{0 0 0} {0 0 1} {0 1 0} {0 1 1} {1 0 0} {1 0 1} {1 1 0} {1 1 1}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; | |
; Mah-jong example | |
; | |
(define $shuntsu : (PatternConstructor [Hai (Collection Hai)] (Collection Hai)) | |
(pattern-constructor [$pat1 $pat2] | |
<cons (& <num $s $n> pat1) | |
<cons <num ,s ,(+ n 1)> | |
<cons <num ,s ,(+ n 2)> | |
pat2>>>)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/home/egi/egison3% egison [0] | |
Egison Version 3.0.8 (C) 2011-2013 Satoshi Egi | |
http://egison.pira.jp | |
Welcome to Egison Interpreter! | |
> (take 10 (match-all primes (list integer) [<join _ <cons $n <cons ,(+ n 2) _>>> [n (+ n 2)]])) | |
{[3 5] [5 7] [11 13] [17 19] [29 31] [41 43] [59 61] [71 73] [101 103] [107 109]} | |
> (take 10 (match-all primes (list integer) [<join _ <cons $n <cons ,(+ n 4) _>>> [n (+ n 4)]])) | |
{[7 11] [13 17] [19 23] [37 41] [43 47] [67 71] [79 83] [97 101] [103 107] [109 113]} | |
> (take 1 (match-all primes (list integer) [<join _ <cons $n <cons ,(+ n 2) <cons ,(+ n 4) _>>>> [n (+ n 2) (+ n 4)]])) | |
{[3 5 7]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/home/egi/egison3% egison [130] | |
Egison Version 3.0.8 (C) 2011-2013 Satoshi Egi | |
http://egison.pira.jp | |
Welcome to Egison Interpreter! | |
> (take 5 (match-all primes (list integer) [<join _ <cons $n <cons ,(+ n 2) <cons ,(+ n 6) _>>>> [n (+ n 2) (+ n 6)]])) | |
{[5 7 11] [11 13 17] [17 19 23] [41 43 47] [101 103 107]} | |
> (take 5 (match-all primes (list integer) [<join _ <cons $n <cons ,(+ n 4) <cons ,(+ n 6) _>>>> [n (+ n 2) (+ n 6)]])) | |
{[7 9 13] [13 15 19] [37 39 43] [67 69 73] [97 99 103]} | |
> | |
Leaving Egison Interpreter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> (take 10 (match-all nats (list integer) [<join _ (& <cons $x _> <join _ (& <cons $y _> <join _ <cons (& ?(lambda [$z] (eq? (* z z) (+ (* x x) (* y y)))) $z) _>>)>)> [x y z]])) | |
{[3 4 5] [6 8 10] [5 12 13] [9 12 15] [8 15 17] [12 16 20] [7 24 25] [15 20 25] [10 24 26] [20 21 29]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> (take 5 (match-all primes (list integer) [<join _ <cons $m <cons (& ?(gte-i? $ (+ 50 m)) $n) _>>> [m n]])) | |
{[19609 19661] [25471 25523] [31397 31469] [31907 31957] [34061 34123]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% egison | |
Egison Version 3.2.0 (C) 2011-2013 Satoshi Egi | |
http://www.egison.org | |
Welcome to Egison Interpreter! | |
> (match-all {1 2 3 4 5} (list integer) [(loop $i [1 2] <join _ <cons $a_i ...>> _) a]) | |
{[|1 2|] [|1 3|] [|2 3|] [|1 4|] [|2 4|] [|3 4|] [|1 5|] [|2 5|] [|3 5|] [|4 5|]} | |
> (match-all {1 2 3 4 5} (list integer) [(loop $i [1 $n] <cons $a_i ...> _) [a n]]) | |
{[[||] 0] [[|1|] 1] [[|1 2|] 2] [[|1 2 3|] 3] [[|1 2 3 4|] 4] [[|1 2 3 4 5|] 5]} | |
> (match-all {1 2 3 4 5} (list integer) [(loop $i [1 $n] <join _ <cons $a_i ...>> _) [a n]]) | |
{[[||] 0] [[|1|] 1] [[|2|] 1] [[|3|] 1] [[|4|] 1] [[|5|] 1] [[|1 2|] 2] [[|1 3|] 2] [[|2 3|] 2] [[|1 4|] 2] [[|2 4|] 2] [[|3 4|] 2] [[|1 5|] 2] [[|2 5|] 2] [[|3 5|] 2] [[|4 5|] 2] [[|1 2 3|] 3] [[|1 2 4|] 3] [[|1 3 4|] 3] [[|2 3 4|] 3] [[|1 2 5|] 3] [[|1 3 5|] 3] [[|1 4 5|] 3] [[|2 3 5|] 3] [[|2 4 5|] 3] [[|3 4 5|] 3] [[|1 2 3 4|] 4] [[|1 2 3 5|] 4] [[|1 2 4 5|] 4] [[|1 3 4 5|] 4] [[|2 3 4 5|] 4] [[|1 2 3 4 5|] 5]} |
OlderNewer