That you can use debug/3 rather than format/2 to print debugging messages is probably old news to other members of this group, but it’s something I only just discovered by picking through the code for concurrent_maplist while figuring out how to do multithreading.
Until now, I’ve been doing “when in doubt, print it out” debugging using format statements. This involved lots of deleting or commenting out, followed by lots of replacing or uncommenting out.
Going through the code in the thread library, I discovered lines like
debug(concurrent, 'Waiting: received ~p', [Exit])
The way this works is that unless
debug(concurrent). is called before the code is run, these messages get ignored.
debug(+Topic). is run first, messages like:
% Waiting: received done(1,["Uno"])
are printed to help figure out what the code is doing.
The details are at A.14 library(debug): Print debug messages and test assertions