Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 282ba76331d32d96ac00e4024a30ac59 > files > 23

erlang-xmlrpc-1.13-2.fc14.x86_64.rpm

-module(fib_server).
-export([handler/2]).

%%
%% A server which calculates Fibonacci values.
%%

handler(_State, {call, fib, [N]}) when integer(N) ->
    {false, {response, [fib(N)]}};
handler(_State, Payload) ->
    FaultString = lists:flatten(io_lib:format("Unknown call: ~p", [Payload])),
    {false, {response, {fault, -1, FaultString}}}.

fib(0) -> 1;
fib(1) -> 1;
fib(N) -> fib(N-1)+fib(N-2).