Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Introdução ao Elixir

No description
by

Guilherme Dutra

on 22 October 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Introdução ao Elixir

Introdução ao Elixir
Elixir
"Elixir is a
functional
, meta-programming aware language built on top of the
Erlang VM
. It is a
dynamic
language with flexible syntax and macro support that leverages Erlang's abilities to build
concurrent, distributed and fault-tolerant
applications with hot code upgrades."

- elixir-lang.org/
Pattern Matching
iex>
a = 1

iex>
1 = a
1

iex>
2 = a
** (MatchError) no match of right hand side value: 1

iex>
list = [1, 2, 3]
[1, 2, 3]

iex>
[a, b, c] = list

iex>
a
1
iex>
b
2
iex>
c
3
Immutability
iex>
name = "elixir"
"elixir"

iex>
cap_name = String.capitalize name
"Elixir"

iex>
name
"elixir"

# pattern matching

fun =
fn
{ a, b } -> { b, a }
end
fun.( { 2, 4 } )

fun =
fn
a, 4 -> a
end
fun.( { 2, 4 } )
Anonymous Functions
iex>
sum = fn (a, b) -> a + b end
#Function<12.17052888 in :erl_eval.expr/5>

iex>
sum.(1, 2)
3

defmodule
Factorial
do
def
of(0),
do
: 1
def
of(n // 1),
do
: n * of(n-1)
end

Fatorial.of(3)
defmodule
Guard
do
def
what_is(x)
when
is_number(x)
do
IO.puts
"#{x} is a number"

end
end

Guard.what_is(12)
fun =
fn

:ok ->
"Okay !"
{_ , error_msg} ->
"Error: #{erro_msg}"
end

fun.(:ok)
# Okay!
fun.({:failed,
"Error 404"
)
# Error: Error 404
| > The amazing Pipe Operator
prepare_filing(sales_tax(Orders.for_customers(DB.find_customers)))
DB.find_customers |> Orders.for_customers |> sales_tax(2013) |> prepare_filing
Named Functions and Guard clauses
Yes, there is a life without loops
[head, tail] = [1, 2, 3, 4, 5]
head
# 1
tail
# [2, 3, 4, 5]
defmodule
MyList
do

def
print_list([]),
do
:
nil

def
print_list([head | tail])
do
IO.inspect head
print_list(tail)

end
end

MyList.print_list [1,2,3,4,5]
Erlang
built on top of Erlang VM
open telecom plataform - OTP
hot code upgrades
Mix - build tool
create
compile
test
manage dependencies
deploy(soon)
ExUnit - test framework
ExUnit.start

defmodule
MyTest
do

use
ExUnit.Case

test
"the truth"

do
assert true

end
end
Processes
actor model
erlang processes != OS processes
messages
defmodule
SpawnBasic
do
def
greet
do
IO.puts
"Hello"
end
end

spawn
(SpawnBasic, greet, [])
#Hello

defmodule
Mom
do

def
allow_son_to_go
do

receive

do
{
:girl
, msg } ->
IO.puts
"Ok baby..you can go but take care"

{ _ , msg } ->
IO.puts
"Ok baby..you can go"

end

end
end

defmodule
Son
do

def
ask_permissions_to_mom(who)
do
pid = spawn(Mom,
:allow_son_to_go
, [])
pid <- {who,
"Can I go?"
}

end
end

Son.ask_permissions_to_mom(
:girl
)
Next steps...
Full transcript