Here are the solutions that I came up with for the études in this book.
Here is a suggested solution for Étude 2-1.
Here is a suggested solution for Étude 2-2.
Here is a suggested solution for Étude 2-3.
Here is a suggested solution for Étude 3-1.
Here is a suggested solution for Étude 3-2.
Here is a suggested solution for Étude 3-3.
Here is a suggested solution for Étude 3-4.
Here is a suggested solution for Étude 4-1.
Here is a suggested solution for Étude 4-2.
Here is another solution for Étude 4-2. This solution uses multiple clauses with guards instead of cond.
Here is a suggested solution for Étude 4-3.
Here is a suggested solution for Étude 4-4.
Here is a suggested solution for Étude 4-5.
Here is a suggested solution for Étude 5-1.
Here is a suggested solution for Étude 5-3.
Here is a suggested solution for Étude 6-1.
Here is a suggested solution for Étude 6-2.
link:code/ch06-02/dates.ex[role=include]
Here is a suggested solution for Étude 6-3 with leap years handled in a different way.
Here is a suggested solution for Étude 6-3.
Here is a suggested solution for Étude 6-4.
Here is a suggested solution for Étude 7-1.
Here is a suggested solution for Étude 7-2.
Here is a suggested solution for Étude 7-3.
Here is a suggested solution for Étude 7-4. The code shown here is the code required to implement the additional protocols; the remaining code is the same as in
Here is a suggested solution for Étude 8-1.
Here is a suggested solution for Étude 8-2.
Here is a suggested solution for Étude 8-3.
Here is a suggested solution for Étude 8-4.
Here is a suggested solution for Étude 8-5.
Here is a suggested solution for Étude 8-6.
Here is a suggested solution for Étude 9-1.
Here is a suggested solution for Étude 10-1.
Here is a suggested solution for Étude 10-2.
Here is a suggested solution for Étude 11-1.
Here is a suggested solution for Étude 12-1.
Here is a suggested solution for Étude 12-2. Since the bulk of the code is identical to the code in the previous étude, the only code shown here is the revised -export list and the added functions.
Here is a suggested solution for Étude 12-3. Since the bulk of the code is identical to the previous étude, the only code shown here is the added and revised code.
# convenience method for startup def start_link do :gen_server.start_link({:global, __MODULE__}, __MODULE__, [], []) end def connect(other_node) do case :net_adm.ping(other_node) do :pong -> IO.puts("Connected to server.") :ok :pang -> IO.puts("Could not connect.") :error end end def report(station) do :gen_server.call({:global, __MODULE__}, station) end def recent() do result = :gen_server.call({:global, __MODULE__}, :recent) IO.puts("Recently visited: #{inspect(result)}") end
Here is a suggested solution for Étude 12-4.
Here is a suggested solution for Étude 13-1.
Here is a suggested solution for Étude 13-2.
Here is a suggested solution for Étude 13-3.