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

Erlang/N2O KNPMeetup

Erlang/N2O KNPMeetup

Small presentation of Erlang and N2O web framework, during KNPMeetup 2015 ( https://github.com/5HT/n2o )

Oleg Zinchenko

January 24, 2015
Tweet

More Decks by Oleg Zinchenko

Other Decks in Programming

Transcript

  1. qsort([]) -> []; qsort([x|Xs]) -> qsort([Y || Y<-Xs, Y <=

    X]) ++ [x] ++ qsort([Y || Y<-Xs, Y > X]). QuickSort
  2. Basis Integer 42 Float 4.2 aka double Atom ok Binary

    <<"Erlang-powa">> Reference #Ref<0.0.0.29> Pid <0.0.42> Port #Port<0.42> Fun #Fun<erl_eval.6.82930912>
  3. Basis 2 List [<<42,1,0,90>>, 1, ok] Tuple {<0.0.16>, 107, 42,

    ["madness", true]} we can force lists type and typify turples named tuples =:= records
  4. Pattern Matching X = 1. [H | T] = [1,

    2, 3, 4]. Y = 2. Y = 3. %% err there {A, B, C} = {ok, X, [“hello”, “knp”, “symfony”]}
  5. Small stuff on Erlang fib(0) -> 0; fib(1) -> 1;

    fib(N) -> fib(N - 1) + fib(N - 2).
  6. Small stuff on Erlang tail_fib(N)-> tail_fib_acc(N, 0, 0, 0). tail_fib_acc(N,

    Counter, Prev, PrevPrev) -> case Counter of N -> Prev + PrevPrev; 0 -> tail_fib(N, Counter + 1, 0, 0); 1 -> tail_fib(N, Counter + 1, 1, 0); _ -> tail_fib(N, Counter + 1, Prev + PrevPrev, Prev) end.
  7. N2O, Idiomatic chat -module ( chat ). event (chat) ->

    wf:send (chat, wf:q (message) ), body () -> wf:async ( fun() -> loop() end, chat ), [ #panel { id=history }, #textbox { id=message }, #button { postback=chat } ]. loop () -> receive Message -> wf:insert_bottom ( history, #span { text=Message } ), wf:flush () end, loop ().