Description
1.1 Aims of This Project
The aims of this project are as follows:
• To give you an introduction to programming in Erlang.
• To expose you to concurrent programming.
1.2 Project Specication
Update your github repository with a directory submit/prj5-sol to contain the
following les:
fn_server.erl This le should implement code for a fn_server Erlang module which supports evaluating a xed function with arbitrary arguments.
Specically, it should export the following functions:
fn_server:start(Fn) Start an Erlang server to compute function Fn
and return its PID. The server should maintain Fn as part of its state.
fn_server:compute(ServerPid, Args) Use the server identied by PID
ServerPid to compute and return the value of applying the associated function Fn to the arguments specied by the list Args.
fn_server:stop(ServerPid) Stop the server identied by PID ServerPid.
rand.erl This le should implement code for a rand Erlang module which
supports the generation of random integers. Specically, it should export
the following functions:
rand:start(Seed) Start an Erlang server to generate random integers
and return its PID. The server should maintain the current Seed as
part of its state.
rand:rand(ServerPid) Use the server identied by PID ServerPid to
generate and return the next random number using the provided
next_rand() function. The Seed stored in the server should be set
to the returned value.
rand:stop(ServerPid) Stop the server identied by PID ServerPid.
1
The le LOG provides an annotated sample log of the operation of these functions.
1.3 Provided Files
The prj5-sol directory contains the following:
fn_server.erl A starting point for the fn-server.erl you are required to
complete.
rand.erl A starting point for the rand.erl you are required to complete.
This le provides the next_rand() function which can be used to generate
the next random number.
fns.erl Functions which can be used for testing the function server.
README A template README; replace the XXX with your name, B-number
and email. You may add any other information you believe is relevant to
your project submission. In particular, you should document the datastructure used for your word-store.
1.4 Hints
• The amount of code you need to write for this project is well under 50
lines.
• The function server is very similar to the data server covered in the lab.
• To apply a function Fn to some list of arguments Args, use Erlang’s apply¬
(Fn, Args).
• The random number generation server needs to maintain the current seed
as part of its state. This can easily be achieved by having the current seed
as an argument to the server function.
• Use io:format() when debugging.
2