Just to clarify, these are refered to as anonymous functions. Which, as mentioned, are nameless and should be called using a dot and may also be defined using the & shorthand. Refer to this lesson for a better overview.
Haha, I have to admit that it was one of the things that I wondered myself - but I think that is also true of other things that are different to what we’re used to (or for some reason or another, feel peculiar to us). Once we learn about them it just makes sense and we move on.
With that said, I have been thinking about whether we could do with a Frequently Asked Questions section, as well as perhaps a Glossary section - for common stuff like this. We can then easily direct people to the associated thread whenever the topic comes up (with the added benefit them many people will browse such sections as well)
It has already been explained in this thread but for additional context this early thread may help as well. I do not think anyone mentions it directly but it is also important to know two things:
Elixir code compiles to Erlang AST
Erlang solves this ambiguity problem by requiring capital letters for variable names and lowercase for atoms (including module and function names). So there is no chance of ambiguity here.
Elixir solves the ambiguity between variable and atom names by prefixing atoms with a colon but including a colon in local function invocation seems like a worse trade-off than a dot for anonymous functions.
I think it is a shame though and easily the biggest remaining wart in the language, and the cost of it is probably a diminished usage of anonymous functions in everyday code.
I do use them as I need them and I like the erlang and elixir way.
In go code I write for work when I have a long function body in legacy code I often see foo() and then searching begins… My first reaction is scanning the list of functions on the right, but it’s not there. Then I scroll up to the current functions head to see if it is passed in as an argument, I don’t even find it there so I scroll even more up and see a dot imported package… I hate this ambiguity…
In elixir and erlang I can see at least if it is a variable or a “real” function.