Top 1,000 Features Creators Resources Extensions Blog Explorer CSV Download
GitHub icon

Elixir

< >

Elixir is an open source programming language created in 2011 by Josรฉ Valim.

#28on PLDB 13Years Old 89kRepos
Download source code:
git clone https://github.com/elixir-lang/elixir

Try now: Riju ยท TIO

Elixir is a functional, concurrent, general-purpose programming language that runs on the Erlang virtual machine (BEAM). Elixir builds on top of Erlang and shares the same abstractions for building distributed, fault-tolerant applications. Elixir also provides a productive tooling and an extensible design. Read more on Wikipedia...


Example from Riju:
IO.puts("Hello, world!")
Example from hello-world:
#!/usr/bin/env elixir IO.puts "Hello World"
# Hello world in Elixir defmodule HelloWorld do IO.puts "Hello, World!" end
Example from Linguist:
%{"cowboy": {:hex, :cowboy, "1.0.0"}, "cowlib": {:hex, :cowlib, "1.0.1"}, "hackney": {:hex, :hackney, "0.14.3"}, "hound": {:hex, :hound, "0.6.0"}, "httpoison": {:hex, :httpoison, "0.5.0"}, "idna": {:hex, :idna, "1.0.1"}, "phoenix": {:hex, :phoenix, "0.10.0"}, "plug": {:hex, :plug, "0.11.1"}, "poison": {:hex, :poison, "1.3.1"}, "ranch": {:hex, :ranch, "1.0.0"}}
Example from Wikipedia:
task = Task.async fn -> perform_complex_action() end other_time_consuming_action() Task.await task
Elixir Keywords
after and catch do else end false fn in nil not or rescue true when

Language features

Feature Supported Token Example
Unicode Identifers โœ“
ฮด = 0.00001
Case Sensitivity โœ“
Exceptions โœ“
raise "oops, something went wrong"
Pattern Matching โœ“
def fib(0), do: 1
def fib(1), do: 1
def fib(n) when n >= 2, do: fib(n-1) + fib(n-2)
Runtime Guards โœ“
def abs(number) when number > 0, do: number
def abs(number), do: -number
Garbage Collection โœ“
Multiline Strings โœ“
template = """
This is the first line.
This is the second line.
This is the third line.
"""
Infix Notation โœ“
seven = 3 + 4
Scientific Notation โœ“
1.23e45
Anonymous Functions โœ“
fn -> IO.puts("hello world") end
Pipes โœ“
"Elixir" |> String.graphemes() |> Enum.frequencies()
Streams โœ“
https://hexdocs.pm/elixir/Stream.html
Macros โœ“
# https://hexdocs.pm/elixir/Macro.html
defmodule Example do
  defmacro macro_inspect(value) do
    IO.inspect(value)
    value
  end
  def fun_inspect(value) do
    IO.inspect(value)
    value
  end
end
Polymorphism โœ“
https://hexdocs.pm/elixir/Protocol.html
Range Operator โœ“
1..3
Single Dispatch โœ“
Maps โœ“
%{key: "value"}
Booleans โœ“ true false
Binary Literals โœ“
# 0b[01]+
Integers โœ“
# \d(_?\d)*
Floats โœ“
# \d(_?\d)*\.\d(_?\d)*([eE][-+]?\d(_?\d)*)?
Hexadecimals โœ“
# 0x[\da-fA-F]+
Octals โœ“
# 0o[0-7]+
Strings โœ“ "
"Hello world"
Lists โœ“
my_list = [1, 2, 3, 4, 5]
Regular Expression Syntax Sugar โœ“
~r/integer: \d+/
Print() Debugging โœ“ IO.puts
Message Passing โœ“
send(pid, :ping)
Line Comments โœ“ #
# A comment
Default Parameters Pattern โœ“
def multiply(a, b \\ 1) do
  a * b
end
Conditionals โœ“
if true do
  IO.puts("Hello world")
end
Assignment โœ“
name = "John"
File Imports โœ“
# Alias the module so it can be called as Bar instead of Foo.Bar
alias Foo.Bar, as: Bar

# Require the module in order to use its macros
require Foo

# Import functions from Foo so they can be called without the `Foo.` prefix
import Foo

# Invokes the custom code defined in Foo as an extension point
use Foo
Comments โœ“
# A comment
Disk Output โœ“
File.write!("helloworld.txt", "Hello, world!\n")
Shebang โœ“
#!/usr/bin/env elixir
Case Insensitive Identifiers X
Multiple Dispatch X
Units of Measure X
Pointers X
Semantic Indentation X
MultiLine Comments X

View source

- Build the next great programming language ยท About ยท Acknowledgements ยท Published by Breck's Lab