We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Explanation of syntax for calling anonymous functions in Elixir
216
clicks
Source: dashbit.co
Elixir requires a dot notation when calling anonymous functions, a design choice made by the language's creator, José Valim. This requirement addresses the identification of functions by their name and arity (i.e., the number of arguments they take). Unlike languages that allow functions with a variadic number of arguments, Elixir and Erlang VM mandate functions to have a fixed arity. Valim presents a hypothetical scenario in a fictional language to illustrate potential issues without the dot, leading to ambiguity in function invocation. Ultimately, the dot helps to distinguish between module function calls and variable function calls, ensuring name-spacing clarity and preventing naming conflicts. In fact, this approach positions Elixir as a Lisp-2 language, offering separate namespaces for variables and function names. This design is comparable to Erlang's syntactical distinction between variables (uppercase) and function names (lowercase). The article concludes by emphasizing the benefit of clarity over expressiveness in Elixir's case and reaffirms the rationale for the dot notation in anonymous function calling.
Related posts
© HashMerge 2024