Perhaps here is something else to clarify. When you call Process.link/1 you are just calling a function, you are not sending a message to another process – just like when you call Enum.join/1 or String.trim/1. Granted, in those functions you have to pass a data structure in to them, but you are not sending a message. Yes, for functions in the Process module, self is implied, and I can see how these are somewhat of a special case, but why would you force the caller to send self, but immediately reject it if it’s not self, when you can just get self yourself?
We do this in registry.ex, or this not the same thing?
@doc false
def register_name({registry, key}, pid) when pid == self() do
case register(registry, key, nil) do
{:ok, _} -> :yes
{:error, _} -> :no
end
end
That’s interesting. I’ve not dug into the internals of Registry yet. I assume there is another function clause that does not have the when pid == self
though.
I do not see another register_name function in the module.
Thanks everyone for taking the time to respond to my questions. It definitely helps!
register_name/2 is a callback that’s required to use alternative process registries with gen_server, etc., so Elixir has no control over its signature. Some process registries (such as global) do support registering processes other than self().
Haha, interesting topic. Maybe because processes in elixir/erlang are a little bit like objects in OOP, and I’m not joking.
It is not a maybe. Processes are what OOP should have been if you listen to Alan Kay.
But somewhere in the middle, people decided to use Simula constructs.