Mix Commands
Mix is Elixir's build tool -- project scaffolding, dependency management, and task runner in one.
IEx -- Interactive Elixir
The Elixir REPL supports auto-complete, inline docs, and runtime debugging.
# Start IEx with your project loaded
iex -S mix
# Inline documentation
iex> h Enum.map/2
iex> h String.split
# Recompile a module without restarting
iex> r MyModule
# Value inspection
iex> i [1, 2, 3]
# Term: [1, 2, 3]
# Type: List
# Length: 3
# Inspect process info
iex> Process.info(self())
# Break out of incomplete expression
iex> #iex:break
# IEx helpers
iex> exports Enum # list public functions
iex> open Enum.map/2 # open source in editor
Core Data Types
| Type | Example | Notes |
|---|---|---|
integer |
42, 0xFF, 1_000_000 |
Arbitrary precision, no overflow |
float |
3.14, 1.0e-3 |
64-bit IEEE 754 doubles |
atom |
:ok, :error, true |
Named constants (booleans are atoms) |
string |
"hello #{name}" |
UTF-8 binaries with interpolation |
list |
[1, 2, 3] |
Linked lists -- prepend is O(1) |
tuple |
{:ok, value} |
Fixed-size, contiguous memory |
map |
%{key: "val"} |
Key-value store, any key type |
keyword |
[name: "Jo", age: 30] |
List of 2-tuples, allows duplicate keys |
struct |
%User{name: "Jo"} |
Tagged map with compile-time checks |
pid |
#PID<0.110.0> |
Process identifier |
mix.exs Project File
defmodule MyApp.MixProject do
use Mix.Project
def project do
[
app: :my_app,
version: "0.1.0",
elixir: "~> 1.17",
start_permanent: Mix.env() == :prod,
deps: deps(),
aliases: aliases()
]
end
def application do
[
extra_applications: [:logger],
mod: {MyApp.Application, []}
]
end
defp deps do
[
{:phoenix, "~> 1.7"},
{:ecto_sql, "~> 3.12"},
{:jason, "~> 1.4"},
{:credo, "~> 1.7", only: [:dev, :test], runtime: false}
]
end
defp aliases do
[
setup: ["deps.get", "ecto.setup"],
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"]
]
end
end