ryanwold.net

A civic-minded citizen seeking the singularity

An entry

Up and Running with Elixir

Date: 2017-01-17
Status: release
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 elixir to install Elixir, which also installs Erlang git clone the phoenix repo. now you have a /phoenix directory within their, install dependencies create a new Phoenix app called splurty cd into /phoenix/splurty, and run mix 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.hex to install hex, which is a package repository, like Ruby .gems or Python eggs. More can be found at https://hex.pm
  • run iex to start an elixir interpreter. This is like Ruby's irb
  • press ctrl + c twice to exit iex
  • type h to see Help
  • try h IO.inspect or any method name instead of inspect to see a function's documentation
  • use v 1 or v 2 or v etc to reference a certain iex value
  • use iex:break if you need to get back to a clean iex prompt
  • mix new codinggnome to create an application called codinggnome in /codinggnome - source code will live in /codinggnome/lib
  • type mix to compile the app's code
  • elixir -h and iex -h to show help
  • iex -S mix - run iex with mix - within the session, type r Module to reload a module, or c lib/module_name.ex to recompile the modulef

Examples

  • irb

2* 12 24

  • type String. then press tab to see a list of functions for the String module

``` File.read("words.txt")

returns

{ :ok, :binary } - a binary "string-like" object (but not a string) ```