The short answer to this is that yes, you can access the genserver by name, but there is no __NAME__.
The nuanced answer is that you can pass the :name option to the GenServer.start/3 or GenServer.start_link/3 function. What you provide as the value of the :name option will become the server’s alias, and you can now “access” the server via the alias wherever you would normally use a pid. You can find more information in the GenServer docs - specifically, search for the phrase “name registration”. (Please note that there are restrictions on what the value of :name can be.
Since there is no __NAME__, what you can do is create a function that takes one parameter (the name of the server), and then delegates to GenServer.stop, which uses the argument to stop the correct server. For example:
def stop(server) do would delegate to GenServer.stop(server, :stop).
It is Saša Jurić and covers a number of techniques for registering and subsequently discovering running processes. It covers a lot of the techniques mentioned here and more.
@CharlesO - I’m glad that this worked, but it does not look like idiomatic Elixir (though I don’t have the context of the rest of the code). Process discovery is a topic that is treated very crisply and clearly by @sasajuric in his book Elixir in Action. If you have the time, his talk (already linked to in this post) is fantastic, but I got more from the book. I’m also writing a post on this topic, but I don’t plan to have that ready until this Saturday.
There is also a tiny library in Erlang, called Syn, where you can easily register process with any name/meta, and also join them into groups.
More about Syn in this post