Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Erlang in The Land of Lisp

Jan Stępień
February 11, 2016

Erlang in The Land of Lisp

As seen on PolyConf 2016, Clojure Remote 2016 and :clojureD 2016.

This talk is dedicated to lessons we’ve learned while designing, developing, and deploying to production our very first Erlang project. The audience of this talk will learn about differences between Clojure and Erlang, both at the linguistic level as well as, even more importantly, at the level of underlying virtual machines. I’m going to discuss how Erlang challenges our methods of building systems in Clojure. I’ll use our new Erlang-based project as a source of concrete differences.

Video: https://www.youtube.com/watch?v=qVMKIKJrUd8

Jan Stępień

February 11, 2016
Tweet

More Decks by Jan Stępień

Other Decks in Programming

Transcript

  1. -module(qsort). -export([qsort/1]). qsort([]) -> []; qsort([Pivot|Rest]) -> qsort([Front || Front

    <- Rest, Front < Pivot]) ++ [Pivot] ++ qsort([Back || Back <- Rest, Back >= Pivot]). en.wikipedia.org/wiki/Erlang (programming language)
  2. $ rebar sh ==> rib (shell) Erlang/OTP 18 Eshell V7.0

    (abort with ^G) 1> sync:go(). Starting Sync (Automatic Code Compiler / Reloader) Scanning source files... ok 2> =INFO REPORT==== 7-Feb-2016::12:21:23 === src/rib.erl:0: Recompiled. =INFO REPORT==== 7-Feb-2016::12:21:23 === rib: Reloaded! (Beam changed.)
  3. pmap(Fun, List) -> Parent = self(), Workers = [spawn(fun() ->

    Parent ! {self(), Fun(X)} end) || X <- List], [receive {Worker, Value} -> Value end || Worker <- Workers].
  4. pmap(Fun, List) -> Parent = self(), Workers = [spawn_link(fun() ->

    Parent ! {self(), Fun(X)} end) || X <- List], [receive {Worker, Value} -> Value end || Worker <- Workers].
  5. pmap(Fun, List) -> Parent = self(), Workers = [spawn_link(fun() ->

    Parent ! {self(), Fun(X)} end) || X <- List], [receive {Worker, Value} -> Value after 1000 -> error(timeout) end || Worker <- Workers].
  6. -module(rib_conn_killer). -export([start_link/0]). start_link() -> {ok, spawn_link(fun go/0)}. go() -> {ok,

    Url} = application:get_env(rib, backend), Headers = [{"connection", "close"}], {ok, _} = httpc:request(get, {Url, Headers}), ok = timer:sleep(30000), go().
  7. -module(rib_limiter). -behaviour(gen_server). start_link(Opts) -> gen_server:start_link(?MODULE, Opts, []). subtract(ServerRef, N) ->

    gen_server:cast(ServerRef, {subtract, N}). init({max, N}) -> {ok, N}. handle_cast({subtract, N}, State) -> NewState = State - N, case NewState >= 0 of true -> {noreply, NewState}; false -> {stop, limit_exceeded, NewState} end.