Created
April 16, 2015 00:49
-
-
Save ne-sachirou/acc578cf5dacd1b59d7e to your computer and use it in GitHub Desktop.
Elixir short sample.
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
defmodule Count do | |
def f parent, cnt do | |
send parent, {:print, cnt} | |
receive do | |
:up -> Count.f parent, cnt + 1 | |
_ -> | |
send parent, {:print, "バカ"} | |
Count.f parent, cnt | |
end | |
end | |
end | |
defmodule Main do | |
def start do | |
pid = spawn Count, :f, [self(), 0] | |
Main.loop pid | |
end | |
def loop pid do | |
send pid, :up | |
receive do | |
{:print, n} -> | |
IO.puts n | |
Main.loop pid | |
_ -> | |
IO.puts "アホ" | |
Main.loop pid | |
after 1000 -> | |
IO.puts "tick" | |
Main.loop pid | |
end | |
end | |
end | |
Main.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment