Skip to content

Instantly share code, notes, and snippets.

View egisatoshi's full-sized avatar

Satoshi Egi egisatoshi

View GitHub Profile
Last login: Mon May 12 19:57:49 on console
USER-no-iMac:~ user$ ruby --version
ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]
USER-no-iMac:~ user$ sudo gem install egison
Password:
Fetching: egison-0.0.2.gem (100%)
Successfully installed egison-0.0.2
Parsing documentation for egison-0.0.2
Installing ri documentation for egison-0.0.2
1 gem installed

Preparation

Build PLT files. (Get types of core libraries.) The file .dialyzer_plt is created in your home directory. It will take time (more than a minute).

$ dialyzer --build_plt --apps erts kernel stdlib crypto mnesia sasl common_test eunit
user =
  { <User 1 "Egison_Lang">
    <User 2 "__Egi">
    ...
   }

follow =
  { <Follow 1 101 201>
    ...
@egisatoshi
egisatoshi / IO from interpreter
Last active August 29, 2015 13:55
Easy access to IO from the prompt. This is a feature from Egison version 3.2.12
% egison
Egison Version 3.2.12 (C) 2011-2014 Satoshi Egi
http://www.egison.org
Welcome to Egison Interpreter!
> (io (each print (take 10 (map itos primes))))
2
3
5
7
11
@egisatoshi
egisatoshi / new feature version 3.2.0
Last active January 2, 2016 02:28
From Egison version 3.2.0, the syntax of loop pattern is changed. The following code is an example.
% 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]}
> (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]}
> (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]}
@egisatoshi
egisatoshi / prime triplet
Created July 8, 2013 15:03
Playing with prime numbers
/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.
@egisatoshi
egisatoshi / twin primes
Created July 8, 2013 14:54
Playing with prime numbers with Egison
/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]}
@egisatoshi
egisatoshi / mah-jong
Last active December 13, 2015 22:19
Mah-jong in next Egison
;
; 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>>>))