3
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

どうでもいいErlang入門

とりあえず入れるだけならパッケージインストールが出来る

Fedora(20)でやる例

$ sudo yum install -y erlang

なお、Riakをyumで入れると自動でErlangも入る

$ sudo yum install -y riak

Hello, World

なぞるととりあえず出来る

sample.erl
-module(sample).
-export([hello_world/0]).

hello_world() -> io:fwrite("Hello, World!\n").

階乗

factorial.erl
-module(factorial).
-export([fac/1]).
fac(0) -> 1;
fac(N) when N>0 ->
Prev = fac(N-1),
N*Prev.

fac() -> io:fwrite(fac(10)).

実行(erlコマンドでファイルを実行する)

$ erl
Eshell V5.10.4  (abort with ^G)
1> c(sample).
{ok,sample}
2> sample:hello_world().
Hello, World!
ok
------
2> c(factorial).
factorial.erl:8: Warning: function fac/0 is unused
{ok,factorial}
3> factorial:fac(3).
6

ガードやパターンマッチでごにょごにょするあたりはHaskellなどと似ている

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
3
Help us understand the problem. What are the problem?