defmodule Say do def hello(thing) do IO.puts "Hello #{thing}" end end Say.hello("PGHRb") ================== iex(1)> Say.hello("PGHrb") Hello PGHrb :ok Friday, September 6, 13
HTTP://WWW.SLIDESHARE.NET/ARBOW/COMPARING-CPP-AND-ERLANG-FOR-MOTOROLA-TELECOMS-SOFTWARE Never completely fails, still handles 25,000 queries/sec Friday, September 6, 13
DAVE THOMAS I’m a language nut. I love trying them out, and I love thinking about their design and implementation. (I know, it’s sad.) I came across Ruby in 1998 because I was an avid reader of comp.lang.misc (ask your parents). I downloaded it, compiled it, and fell in love. As with any time you fall in love, it’s difficult to explain why. It just worked the way I work, and it had enough depth to keep me interested. ... - Foreword to Programming Elixir Friday, September 6, 13
Fast forward 15 years. All that time I’d been looking for something new that gave me the same feeling. I came across Elixir a while back, but for some reason never got sucked in. But a few months ago I was chatting with Corey Haines. I was bemoaning the fact that I wanted to find a way to show people functional programming concepts without the kind of academic trappings those books seem to attract. He told me to look again at Elixir. I did, and I felt the same way I felt when I first saw Ruby. ... - Foreword to Programming Elixir DAVE THOMAS Friday, September 6, 13
DAVE THOMAS So now I’m dangerous. I want other people to see just how great this is. I want to evangelize. So my first step is to write a book. - Foreword to Programming Elixir Friday, September 6, 13
“With both Pragmatic Press and O'Reilly racing to get into Elixir I knew something was happening on the Erlang VM, and I didn’t know about this. Boy am I out of touch.” - Blog Post - http://joearms.github.io/2013/05/31/a-week-with-elixir.html JOE ARMSTRONG Friday, September 6, 13
JOE ARMSTRONG “I downloaded elixir last week and started playing … It didn’t take long, but pretty soon my gut feeling kicked in. This is good shit.” - Blog Post - http://joearms.github.io/2013/05/31/a-week-with-elixir.html Friday, September 6, 13
“What Elixir brings to the table is a complete different surface syntax, inspired by Ruby. What you might call a ‘non-scary’ syntax, and a load of extra goodies.” - Blog Post - http://joearms.github.io/2013/05/31/a-week-with-elixir.html JOE ARMSTRONG Friday, September 6, 13
“I’ll just say that Elixir has got a heck of lot of things right, and the good things far outweigh the bad things.” “This has been my first week with Elixir, and I’m pretty excited.” - Blog Post - http://joearms.github.io/2013/05/31/a-week-with-elixir.html JOE ARMSTRONG Friday, September 6, 13
WEBSCALE? DISTRIBUTED, RELIABLE, SOFT REAL-TIME CONCURRENT SYSTEMS. TELECOMMUNICATION SYSTEMS, E.G. CONTROLLING A SWITCH OR CONVERTING PROTOCOLS. SERVERS FOR INTERNET APPLICATIONS, E.G. A MAIL TRANSFER AGENT, AN IMAP-4 SERVER, AN HTTP SERVER OR A WAP STACK. TELECOMMUNICATION APPLICATIONS, E.G. HANDLING MOBILITY IN A MOBILE NETWORK OR PROVIDING UNIFIED MESSAGING. DATABASE APPLICATIONS WHICH REQUIRE SOFT REALTIME BEHAVIOUR. HTTP://WWW.ERLANG.ORG/FAQ/INTRODUCTION.HTML#ID49576 Friday, September 6, 13
ELIXIR IS EVERYTHING GOOD ABOUT ERLANG AND NONE — ALMOST NONE — OF THE BAD. THAT’S A BOLD STATEMENT, RIGHT? ELIXIR IS WHAT WOULD HAPPEN IF ERLANG, CLOJURE, AND RUBY SOMEHOW HAD A BABY AND IT WASN’T AN ACCIDENT. -- DEVIN TORRES HTTP://DEVINTORR.ES/BLOG/2013/01/22/THE- EXCITEMENT-OF-ELIXIR/ Friday, September 6, 13
USE ERLANG LIBRARIES defmodule GitHub do ... def process_response_body(body) do json = :jsx.decode to_binary(body) json2 = Enum.map json, fn ({k, v}) -> { binary_to_atom(k), v } end :orddict.from_list json2 end end Friday, September 6, 13
ELIXIR WORKFLOW (IN VIM & TMUX) # Install vim-elixir # Add to .vimrc nnoremap e :!elixir % nnoremap ee :!iex -r % -S mix # Use this in shell for repl $ iex -r lib/concurrency.ex -S mix # Use this in shell for tests $ elixir test/concurrency_test.ex $ mix test Friday, September 6, 13
PSEUDO-LIVE CODING #Calculate the area of a rectangle #create a function and assign to variable area = fn(w, h) -> w * h end # call function area.(3, 5) #=> 15 Friday, September 6, 13
Code.load_file("lib/concurrency_pre.ex") ExUnit.start defmodule AreaTest do use ExUnit.Case, async: true test "area" do area = fn(w, h) -> w * h end assert area.(3,5) == 15 end end beastie:concurrency elixir test/concurrency_pre_test.exs . Finished in 0.08 seconds (0.08s on load, 0.00s on tests) 1 tests, 0 failures TESTS (VERSION 1) Friday, September 6, 13
defmodule Concurrency do def area_loop do receive do {:die} -> IO.puts “Bye cruel world!” input -> IO.puts Geometry.area(input) area_loop() end end def start do spawn(fn -> Concurrency.area_loop() end) end end defmodule Geometry do def area({ :rectangle, w, h }) do w * h end def area({ :circle, r }) do :math.pi * r * r end def area({ :cone, r, h }) do :math.pi * r * :math.sqrt( r * r + h * h) end end Friday, September 6, 13
# Tuples - all the way down {:rectangle, 4, 5} # Linked Lists - Yay recursion! [head | tail] # Records - like structs defrecord FileInfo, atime: nil, accesses: 0 # Protocols - for polymorphism defprotocol Blank do @doc "Returns true if data is considered blank/empty" def blank?(data) end # Homoiconic - turtles all the way down Elixir is written in Elixir (esp macros) OTHER GOODIES Friday, September 6, 13
LIBRARIES OF NOTE Ruby Elixir Link Rails Dynamo https://github.com/elixir-lang/dynamo Active Record Atlas https://github.com/chrismccord/atlas TestUnit ExUnit http://elixir-lang.org/getting_started/ex_unit/1.html Bundler & Rake Mix http://elixir-lang.org/getting_started/mix/1.html vim-ruby vim-elixir https://github.com/elixir-lang/vim-elixir Friday, September 6, 13