Skip to content

Instantly share code, notes, and snippets.

Avatar

Satoshi Egi egisatoshi

View GitHub Profile
View nikoli.egi
concat (matchAll (["akira", "susumu", "tamotsu", "tomo"], ["blue", "green", "red", "white"], [1, 2, 3, 4])
as (list something, multiset something, multiset something) with
| ([$x_1, $x_2, $x_3, $x_4], [$y_1, $y_2, $y_3, $y_4], [$z_1, $z_2, $z_3, $z_4])
-> matchAll [(x_1, y_1, z_1), (x_2, y_2, z_2), (x_3, y_3, z_3), (x_4, y_4, z_4)]
as set (eq, eq, eq) with
| (#"akira", #"blue", !#1) ::
(#"susumu", !#"green", !#4) ::
(_, #"red", #2) ::
(_, #"white", $n) ::
(#"tamotsu", _, #(n - 1)) :: _
View primes.egi
(take 6 (match-all primes (list integer)
[<join _ <cons $p <cons ,(+ p 2) _>>>
[p (+ p 2)]]))
View egison-programming-contest.md

Egisonプログラミングコンテスト2018問題集

パターンマッチ指向プログラミング

関数型プログラミングにおいて基本的なリスト操作関数を再帰を使わずに,単一のmatch-all式で定義できる. たとえば,map関数は以下のように定義できる.

(define $map
  (lambda [$f $xs]
View anagram.egi
% cat anagram.egi
(define $anagram?
(lambda [$xs $ys]
(match ys (multiset eq)
{[,xs #t]
[_ #f]})))
(anagram? (between 1 31) (reverse (between 1 31)))
(anagram? (between 1 31) (reverse (between 2 32)))
% time egison -t anagram.egi
View shitennou.egi
(filter (match-lambda (list something)
{[(& <snoc ,D _>
<join _ <cons ,B <join _ <cons ,C _>>>>
<snoc _ <snoc _ <nioj _ <snoc ,B _>>>>
<join _ <cons ,C <join _ <cons ,A _>>>>)
#t]
[_ #f]})
(match-all {A B C D} (multiset something)
[<cons $a <cons $b <cons $c <cons $d <nil>>>>> {a b c d}]))
@egisatoshi
egisatoshi / tensor.egi
Last active May 19, 2016
tensor design
View tensor.egi
;;
;; Tensor
;;
[| x |]
;=>
x
(+ 1 [|1 2 3|])
;=>
@egisatoshi
egisatoshi / taylor-expansion.egi
Created May 17, 2016
Multi variate Taylor Expansion
View taylor-expansion.egi
(define $∇
(lambda [$f $xs]
(generate-tensor
1#(∂/∂ f (nth %1 xs))
{(length xs)})))
(define $nabla ∇)
(define $taylor-expansion2
(lambda [$f $xs $as]
@egisatoshi
egisatoshi / emacs_egison.el
Last active Aug 4, 2017
emacs seting for Egison
View emacs_egison.el
;; Egison mode
(load-file "~/egison/elisp/egison-mode.el")
(autoload 'egison-mode "egison-mode" "Major mode for editing Egison code." t)
(setq auto-mode-alist
(cons `("\\.egi$" . egison-mode) auto-mode-alist))
(load-file "~/elisp/xah-math-input/xah-math-input.el")
(global-set-key "\C-q" 'xah-math-input-change-to-symbol)
@egisatoshi
egisatoshi / maclaurin-expansion.md
Last active Apr 14, 2016
MacLaurin expansion on shell
View maclaurin-expansion.md
% egison -T -e '(maclaurin-expansion (cos x) x)'                                        
1
0
(/ (* -1 x^2) 2)
0
(/ x^4 24)
0
(/ (* -1 x^6) 720)
0
@egisatoshi
egisatoshi / shell18.egi
Last active Sep 2, 2015
shell game 18 q8
View shell18.egi
cat number | egison -F1s -s '(match-all-lambda (list string) [<cons <join _ <cons $x <cons $y <join $s <cons ,x <cons ,y $t>>>>>> _> [x y (take-while eq? (zip (unpack s) (unpack t)))]])'