Programming Erlang Book Club

I’ve read chapter 8, or better skimmed, as Joe recommended :wink:
Most interesting thing for me: Dynamic code loading. A very nice thing in Erlang :slight_smile:

Also I started the exercises, but not yet finished:

Exercise 8.1
count_dict_exports() ->
    Modinfo = dict:module_info(),
    {_, Exports} = lists:keyfind(exports, 1, Modinfo),
Exercise 8.2
count_exports(Mod) ->
    {_, Exports} = lists:keyfind(exports, 1, Mod:module_info()),

module_fn_count() ->
    List = code:all_loaded(),
    Touples = [{Module, count_exports(Module)} || {Module, _} <- List],

max_exports({Mod, Count}, []) -> {Mod, Count};
max_exports({Mod, Count}, [{_, C} | T]) when Count > C-> max_exports({Mod, Count}, T);
max_exports({_, Count}, [{M, C} | T]) when Count =< C-> max_exports({M, C}, T).

    max_exports({init, 0}, module_fn_count()).

Still thinking how I should solve the next Exercise :smiley:
Hope you’ll catch up soon, it’ll be very interesting to compare our solutions.

1 Like

I’m so sorry for not being able to read anymore Rainer! This time of year is always a bit hectic for me, hopefully I’ll be able to get back to it soon :smiley: Hopefully it’s given some time for @DevotionGeo to catch up as well :nerd_face:

What do you think of the book so far? Dynamic code loading - I can’t wait to get to that!

My time is also very limited at the moment, but usually I’m reading a bit just before sleeping :wink:
I like the book, but the more I progress the more annoyed I get by C# (my daily business) :stuck_out_tongue: I’m liking the Erlang syntax, which came unexpected :slight_smile:

I continued with the exercises, so here’s the second (of three) part from 8.2:

Exercise 8.2 part 2 (most common function name)

all_functions() ->
    Exports = [lists:keyfind(exports, 1, Module:module_info()) || {Module, _} <- code:all_loaded()],
    Functions = lists:flatten([Funlist || {exports, Funlist} <- Exports]),

get_function_counts([{Funname, _} | T])->
    case get(Funname) of
        undefined -> put(Funname, 1);
        X -> put(Funname, X + 1)
get_function_counts([]) -> get().

most_common_funname() ->
    [{Funname, _} | _] = lists:sort(fun({_, A}, {_, B}) -> A > B end, get_function_counts(all_functions())),

I really wonder how someone experienced wold solve this. I used the process dictionary that was introduced in chapter 8 as a mutable data structure, but I think this can’t be considered ‘good practice’…

1 Like

Thanks to all the encouraging comments in this thread, I ordered the book. It arrives on Saturday! I’ll join y’all then!


Whoo hooo welcome to the club @mafinar :+1: :+1: :+1:

I hope to get back in to this in the next week or two so you have plenty of time to catch up :nerd_face:

Reading the ToC and sample chapter, I got the idea that this book is no just for Erlang, but also an invaluable resource to learn about OTP, kinda like prepping you for the O’Reilly book (Designing for Scalability with Erlang/OTP), I could be wrong though, can’t judge book by the cover.

1 Like

I haven’t got to the OTP bits yet but yes, I expect it will leave you with a really good grounding in it. Are you a slow/fast reader? I am pretty slow unfortunately - so I expect you will overtake me in no time :joy:

I am an insanely fast reader. Finished “Getting Clojure” minus the Interoperating with Java and Macro chapters in a day to revise Clojure. But still, this is ~500 pages, reading Erlang hurts my eyes and I am no longer unemployed so ¯_(ツ)_/¯

1 Like

I wish I was as fast!! :joy:

I think you may find you grow to like the Erlang syntax, at least I think that seems to be the case for a fair amount of people :blush:

1 Like

I do like to write in it, but when reading it get tricky for me- I’m the slow writer fast reader type. The Pascal case atoms and lower case variables slow my reading speed. Oh wait, did I just get them reversed? (See what I mean?) Also this won’t go away because every time my muscle memory settles down a little, Elixir will retune it.

But to be honest, Erlang is very simple. Much simpler than any non-Lisp languages I have encountered. That’s what makes me want to learn it well.

1 Like

That’s something I was astonished about, after reading chapter 8 “The Rest of Sequential Erlang”. The basic concepts are simple yet so powerful.

Looking forward to you catching up :slight_smile:

Meanwhile, i did the last exercise of chapter 8:

Exercise 8.2 part 3 (unambiguous function names)
unambiguous_function() ->
    Exports = [Module:module_info(exports) || {Module, _} <- code:all_loaded()],
    Functions = lists:flatten(lists:map(fun(F) -> function_names_in_module(F, []) end, Exports)),
    unambiguous_elements(Functions, []).

function_names_in_module([{Funname, _}| T], Acc) ->
    case lists:member(Funname, Acc) of
        true -> function_names_in_module(T, Acc);
        false -> function_names_in_module(T, [Funname | Acc])
function_names_in_module([], Acc) -> Acc.

unambiguous_elements([Funname|T], Acc) ->
    case lists:member(Funname, Acc) of
        true -> unambiguous_elements(T, Acc);
        false -> unambiguous_elements(T, [Funname | Acc])
unambiguous_elements([], Acc) -> Acc.

I think there’s an easier solution, but I’m doing it at night with a tired brain :smiley:

1 Like

It arrived early! Can’t wait to start

1 Like

Whoo hoo!!!

Doesn’t it feel kinda special in your hands? Maybe it’s just me but I really wanted to get the printed book as it would feel like there’s a little bit of Joe here - and it does too! Aren’t we a funny species? :upside_down_face:

I will look forward to seeing you get through this book :nerd_face:


I could imagine Joe speaking those lines as I was reading the first page :sob:

Such a well introduction, is the rest of the book as enlightening?


If you like what you’ve read so far you are going to love the rest of it (at least based on what I’ve read so far myself).

Joe’s personality shines through very strongly - it will fill you both with joy and sorrow - joy because it’s him (and almost as if he’s there with you) and sorrow because he’s no longer around, and because you won’t be able to tell him how awesome you’re finding Erlang thanks to him/his book :cry:

It’s far from depressing tho - I don’t think anyone could feel depressed in the presence of Joe… and in this book his presence is most definitely felt :orange_heart:

1 Like

Hi everybody! I’m back after a long break. My 4 day’s trip got stretched to almost 3 weeks, and it looks like I won’t be able to open the book for the rest of this year because of the tasks held. Where is everybody in the book? @mafinar, welcome to the club!


I didn’t make any progress on the book, instead I’m solving Advent of Code with Erlang when I find some time :slight_smile:


Welcome back DG - I hope you had a nice trip :smiley:

I’ve not made much progress tbh but like you hope to get back to it soon. Rainer is steaming ahead :rofl: and from what Mafinar has said, he may be flying through it too :joy:

I would like to place my bet now that I will probably be the last to finish the book :hear_no_evil:

1 Like

As I’m busy with Advent of Code you have some time to catch up :smiley:


Thank you!
I enjoyed the trip a lot. :slight_smile:

1 Like