In the fifo.erl
module you’ve implemented a functional FIFO queue. After each
push or pop operation on the queue a new version of the queue is returned.
A common pattern in Erlang is to provide services as separate processes. If we keep the FIFO queue as a separate process, we can use the PID to the FIFO process as a reference to the FIFO. When we update the state of the FIFO, the PID remains the same.
Open the moudle-8/src/sfifo.erl
module. This module exports a number of functions. The first
of these exported functions is sfifo:new/0
which spawns a new process running
the loop/1
function. The state of the loop/1
function is a functional FIFO
queue implemented in the module-8/src/fifo.erl
module.
Look at the generated html documentation for the sfifo.erl
module.
To inspect and modify the state of the FIFO queue, messages can be sent to the
FIFO process and received in the loop/1
function.
It is good practice to hide the message passing protocol inside a functional
interface. The following functions are already implemented:
sfifo:new/0
sfifo:size/1
sfifo:empty/1
Todo
Your task is to provide working implementations of the following interface functions:
sfifo:pop/1
sfifo:push/2
You will also need to make changes to the loop/1
function.
There are a number of EUnit test cases at the end of sfifo.erl
file.
Repeat the following cycle.
$ make
$ make test_sfifo