Up and Running with Elixir
Date:
2017-01-17
Tags:
elixir
programming
experience-report
I've heard good things about Elixir and its web framework, Phoenix.
Getting Started
I'm using MacOSX, so I had to do a few things to get started:
- run
brew install elixirto install Elixir, which also installs Erlang git clone the phoenix repo. now you have a/phoenixdirectory within their, install dependencies create a new Phoenix app calledsplurtycd into/phoenix/splurty, and runmix phoenix.server, which starts a web server on port 4000
I'm running Elixir 1.8.1.
Terminology
Elixir, like most languages, has distinct names to represent common programming language concepts. This Terminology section is to track and define these concepts like a glossary.
- module - is like a class in Ruby
- application -
- OTP framework -
- processes
- Phoenix framework - provides an HTML frontend
Other words
- concurrent programming
- functional language
- application state
Commands
- run
mix local.hexto installhex, which is a package repository, like Ruby .gems or Python eggs. More can be found at https://hex.pm - run
iexto start an elixir interpreter. This is like Ruby'sirb - press
ctrl + ctwice to exitiex - type
hto see Help - try
h IO.inspector any method name instead ofinspectto see a function's documentation - use
v 1orv 2orv etcto reference a certainiexvalue - use
iex:breakif you need to get back to a cleaniexprompt mix new codinggnometo create an application calledcodinggnomein/codinggnome- source code will live in/codinggnome/lib- type
mixto compile the app's code elixir -handiex -hto show helpiex -S mix- runiexwithmix- within the session, typer Moduleto reload a module, orc lib/module_name.exto recompile the modulef
Examples
irb
2* 12
24
- type
String.then presstabto see a list of functions for theStringmodule
``` File.read("words.txt")
returns
{ :ok, :binary } - a binary "string-like" object (but not a string) ```