Paste: hotswap.erl

Author: Arrogant
Mode: erlang
Date: Wed, 10 Nov 2010 00:13:55
Plain Text |
-module(hotswap).
-export([echoloop/0, factloop/0, factorial/1]).

factorial(N) -> factorial(N, 1).

factorial(0, A) -> A;
factorial(1, A) -> A;
factorial(N, A) -> factorial(N - 1, N * A).

factloop() ->
	receive
		{fact, N} ->
			io:format("~p~n", [factorial(N)]),
			factloop();
		{become, Other} ->
			Other()
	end.

echoloop() ->
	receive
		{echo, Message} ->
			io:format("~p~n", [Message]),
			loop();
		{become, Other} ->
			Other()
	end.

New Annotation

Summary:
Author:
Mode:
Body: