From Just Solve the File Format Problem
Jump to: navigation, search
File Format
Name Elixir
Extension(s) .ex, .exs
Wikidata ID Q5362035
Released 2011

Elixir is a functional programming language that builds on Erlang and uses its virtual machine (the Elixir compiler produces BEAM files used by this). It has concurrently running processes which can communicate with one another; an Elixir module can freely spawn them and this is a common means of organizing Elixir applications. There are also standard library functions for doing TCP functions such as making and accepting connections on a port, enabling the creation of clients and servers, which act just like local processes for the purpose of exchanging messages so that program code can easily be adapted to distributed networks.

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?

Another notable feature of Elixir is the pipe operator, |>, which works similarly to the Unix pipe to send the output of one operation as input to another. When this is done with operations that act on all elements of a list, it can quickly transform and filter the list's elements.

The Elixir compiler includes a command line option "format" which reformats the code in the current project, fixing such things as indentation and line spacing to follow a consistent standard, so you don't have to get all of this right when you're typing the code.

File extensions

  • .ex is the normal extension for Elixir files defining a module, intended to be compiled.
  • .exs is for files used in scripting; they also contain Elixir code, but are intended to be run immediately (e.g., as tests) without saving compiled files for future use.


Personal tools