Skip to content

Instantly share code, notes, and snippets.

View egisatoshi's full-sized avatar

Satoshi Egi egisatoshi

View GitHub Profile
@egisatoshi
egisatoshi / install-egison-to-make-pkg.sh
Last active August 29, 2015 14:24
Egison package for Mac
#!/bin/sh
sudo rm -rf .cabal .ghc /Library/Egison
mkdir .ghc
cabal update
cp my-cabal/config .cabal/config
sudo cabal update
sudo cabal install egison egison-tutorial
sleep 3
sudo rm -rf /Library/Egison/lib/ /Library/Egison/logs/ /Library/Egison/repo-cache/
@egisatoshi
egisatoshi / echo_server.erl
Created April 3, 2015 03:32
Very Simple Echo Sever in Erlang
-module(echo_server).
-export([start/0,stop/1]).
-define(PORT, 12321).
start() ->
Options = [binary, {packet, raw}, {active, true}, {reuseaddr, true}],
case gen_tcp:listen(?PORT, Options) of
{ok, Listen} -> spawn(fun() -> acceptor_loop(Listen) end),
@egisatoshi
egisatoshi / triangles.egi
Last active August 29, 2015 14:13
Find all triangles
(define $points
{[3 1] [4 5] [7 7] [8 1] [1 9] [3 8] [3 1]})
(define $on-a-line?
(match-lambda [[integer integer] [integer integer] [integer integer]]
{[[[$x1 $y1] [$x2 $y2] [$x3 $y3]]
(eq? (abs (* (- y2 y1) (- x3 x1)))
(abs (* (- y3 y1) (- x2 x1))))]}))
; Enumerate triangles
@egisatoshi
egisatoshi / fun.egi
Last active August 29, 2015 14:13
Egison version of this Prolog program https://gist.github.com/GRGSIBERIA/c61e05f3fbb4332bf81e
(define $worriors
{["nagisa_misumi" "futari_ha" "black"]
["honoka_yukishiro" "futari_ha" "white"]
["hikari_kujo" "max_heart" "luminus"]
["saki_hyuga" "splash_star" "bloom"]
["mai_misho" "splash_star" "eaglette"]
["nozomi_yumehara" "yes" "dream"]
["rin_natsuki" "yes" "rouge"]
["urara_kasugano" "yes" "lemonade"]
["komachi_akimoto" "yes" "mint"]
@egisatoshi
egisatoshi / old_egison_wiki.md
Last active August 29, 2015 14:12
old wiki (内容が古くなったので移動)

Welcome to the egison wiki!

How to start Development

Checkout Egison

$ git clone https://github.com/egisatoshi/egison.git
@egisatoshi
egisatoshi / Egison_command_tutorial_ja.md
Last active January 1, 2016 07:24
Egisonコマンドラインチュートリアル

Egisonコマンドラインチュートリアル

式を評価

--evalまたは-eオプションで引数の式を評価できます。 式はシングルクォート(`)で囲みます。

$ egison -e '(take 10 primes)'
{2 3 5 7 11 13 17 19 23 29}
@egisatoshi
egisatoshi / Dockerfile
Created November 17, 2014 04:50
Dockerfile for Egison
FROM phusion/baseimage:latest
MAINTAINER Satoshi Egi
RUN apt-get update
RUN apt-get -y install libncurses-dev
RUN apt-get -y install haskell-platform
RUN cabal update
RUN cabal install egison
ENV PATH /root/.cabal/bin:$PATH
@egisatoshi
egisatoshi / mod.egi
Created August 21, 2014 04:36
Module System of Egison (from version 3.4.0)
(module $Main
{
[String {string}] ; import only string
[$S [String {append concat}]] ; import only append and concat (with 'S.' as prefix)
[$S String] ; import all exported functions (with 'S.' as prefix)
}
{main} ; export main
)
(define $main
@egisatoshi
egisatoshi / file0.txt
Created July 9, 2014 09:12
続編 - RubyにHaskellよりも強力なパターンマッチを実装した ref: http://qiita.com/egisatoshi/items/dfa13e45edbc71430048
require 'egison'
require 'prime'
include Egison
twin_primes = match_stream(Prime) {
with(List.(*_, _x, __("x + 2"), *_)) {
[x, x + 2]
}
}
@egisatoshi
egisatoshi / gist:b25a6207413d0e106bec
Last active August 29, 2015 14:03
range pattern
> (match-all (between 1 100) (set integer) [<cons (& ?(lte? 32 $) ?(lt? $ 64) $x) _> x])
{32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63}
> (car (match-all (between 1 100) (set integer) [<cons (& ?(lte? 32 $) ?(lt? $ 64) $x) _> x]))
32