下を参考にLisp界で有名なたらい回し関数を書いてみた。
青木日記 2003-03-15
.......Erlangでだけどね。
%% Author: Ehren %% Created: 2009/11/13 %% Description: TODO: Add description to foo -module(foo). %% %% Exported Functions %% -export([main/0,tarai/3]). %% %% Local Functions %% main() -> io:format("~p~n",[tarai(12,6,0)]). tarai(X,Y,Z) -> if X =< Y -> Y; true -> tarai(tarai(X-1,Y,Z), tarai(Y-1,Z,X), tarai(Z-1,X,Y)) end.
実行時間は以下のような感じ。これだけだと速いんだか遅いんだかわからないので後日多言語の時間を計測してみます。
$time erl -noshell -run foo main -run init stop 12 real 0m2.612s user 0m1.425s sys 0m0.035s
参考
↓シェルでの実行には以下を参考にさせて頂きました。先人に感謝。
Erlang/基礎 - Glamenv-Septzen.net