LoginSignup
2
3

More than 5 years have passed since last update.

どうでもいいErlang入門

Last updated at Posted at 2014-11-08

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

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などと似ている

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3