|Line 3:||Line 3:|
Revision as of 18:45, 23 June 2022
Elixir is a functional programming language that builds on Erlang and uses its virtual machine.
As with Clojure, the number of arguments a function takes is referred to as its "arity". Functions of the same name and different arity can coexist. What's more, you can have constants as parameters in the function definition, so that
def testfn(42) defines a function that only activates when its parameter equals 42, and this can coexist with other definitions of
testfn that activate on different parameter values (but all such functions with the same name and arity are treated as one function for the purpose of other language features that let functions be passed as values).
Since you can also have arguments with default values so they can be omitted on function invocation, there can be conflicts between a version of a function with arity 3 (but one of the parameters optional) and one with arity 2; these are noted in compiler warnings.
Most languages these days include in their data structures a form of associative array, and Elixir is no exception; its version is called a "map" (there's also a specialized variant called "keyword list"), and it allows any of its data types to be a key in a map; yes, you can even have a map using other maps as keys (which probably belongs in the category of things you can do in this language but probably shouldn't). When a map is displayed in its entirety, you can see the intrinsic sorting order for Elixir values, which extends across all of its data types so that a number like 3 unambiguously sorts before a string like 'abc'. Also, there are two distinct types of strings, using single and double quotes, so 'abc' and "abc" are distinct values and 'abc' sorts before "abc"; 'zzz' even sorts before "aaa". Got it?