I have stumbled upon a piece of code that I can't quite understand. It looks like this:
% spawn process which waits for a message and prints it
Pid = spawn(fun() ->
receive
X -> io:fwrite("I received: ~p~n", [X])
end
end),
% send a message to the new process
Pid ! {message, "Hello"}.
In the last line, is "message" an atom that is defined in the module? I can't really understand that part.
My attempt at understanding it would be this: we save things in tuples where the first element is descriptive of the content. For example: {celsius, 55}. What is less clear is that the atom message is not defined in the module. Do you have to define it? No declaration is necessary so I guess you don't have to define the atom before using it. Am I correct?
Thanks for the help!
The code is from here.