mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-06 14:56:54 +02:00
Fix bad case in the Elixir language
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
language: elixir
|
language: Elixir
|
||||||
contributors:
|
contributors:
|
||||||
- ["Joao Marques", "http://github.com/mrshankly"]
|
- ["Joao Marques", "http://github.com/mrshankly"]
|
||||||
translators:
|
translators:
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
language: elixir
|
language: Elixir
|
||||||
contributors:
|
contributors:
|
||||||
- ["Joao Marques", "https://github.com/mrshankly"]
|
- ["Joao Marques", "https://github.com/mrshankly"]
|
||||||
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
||||||
@@ -13,16 +13,15 @@ It's fully compatible with Erlang, but features a more standard syntax
|
|||||||
and many more features.
|
and many more features.
|
||||||
|
|
||||||
```elixir
|
```elixir
|
||||||
|
|
||||||
# Single line comments start with a number symbol.
|
# Single line comments start with a number symbol.
|
||||||
|
|
||||||
# There's no multi-line comment,
|
# There's no multi-line comment,
|
||||||
# but you can stack multiple comments.
|
# but you can stack multiple comments.
|
||||||
|
|
||||||
# To use the elixir shell use the `iex` command.
|
# To use the Elixir shell use the `iex` command.
|
||||||
# Compile your modules with the `elixirc` command.
|
# Compile your modules with the `elixirc` command.
|
||||||
|
|
||||||
# Both should be in your path if you installed elixir correctly.
|
# Both should be in your path if you installed Elixir correctly.
|
||||||
|
|
||||||
## ---------------------------
|
## ---------------------------
|
||||||
## -- Basic types
|
## -- Basic types
|
||||||
@@ -50,7 +49,7 @@ elem({1, 2, 3}, 0) #=> 1
|
|||||||
head #=> 1
|
head #=> 1
|
||||||
tail #=> [2,3]
|
tail #=> [2,3]
|
||||||
|
|
||||||
# In elixir, just like in Erlang, the `=` denotes pattern matching and
|
# In Elixir, just like in Erlang, the `=` denotes pattern matching and
|
||||||
# not an assignment.
|
# not an assignment.
|
||||||
#
|
#
|
||||||
# This means that the left-hand side (pattern) is matched against a
|
# This means that the left-hand side (pattern) is matched against a
|
||||||
@@ -83,7 +82,7 @@ string.
|
|||||||
<<?a, ?b, ?c>> #=> "abc"
|
<<?a, ?b, ?c>> #=> "abc"
|
||||||
[?a, ?b, ?c] #=> 'abc'
|
[?a, ?b, ?c] #=> 'abc'
|
||||||
|
|
||||||
# `?a` in elixir returns the ASCII integer for the letter `a`
|
# `?a` in Elixir returns the ASCII integer for the letter `a`
|
||||||
?a #=> 97
|
?a #=> 97
|
||||||
|
|
||||||
# To concatenate lists use `++`, for binaries use `<>`
|
# To concatenate lists use `++`, for binaries use `<>`
|
||||||
@@ -116,7 +115,7 @@ genders.gillian #=> "female"
|
|||||||
5 * 2 #=> 10
|
5 * 2 #=> 10
|
||||||
10 / 2 #=> 5.0
|
10 / 2 #=> 5.0
|
||||||
|
|
||||||
# In elixir the operator `/` always returns a float.
|
# In Elixir the operator `/` always returns a float.
|
||||||
|
|
||||||
# To do integer division use `div`
|
# To do integer division use `div`
|
||||||
div(10, 2) #=> 5
|
div(10, 2) #=> 5
|
||||||
@@ -174,7 +173,7 @@ else
|
|||||||
"This will"
|
"This will"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remember pattern matching? Many control-flow structures in elixir rely on it.
|
# Remember pattern matching? Many control-flow structures in Elixir rely on it.
|
||||||
|
|
||||||
# `case` allows us to compare a value against many patterns:
|
# `case` allows us to compare a value against many patterns:
|
||||||
case {:one, :two} do
|
case {:one, :two} do
|
||||||
@@ -307,7 +306,7 @@ Geometry.area({:circle, 3}) #=> 28.25999999999999801048
|
|||||||
# Geometry.area({:circle, "not_a_number"})
|
# Geometry.area({:circle, "not_a_number"})
|
||||||
#=> ** (FunctionClauseError) no function clause matching in Geometry.area/1
|
#=> ** (FunctionClauseError) no function clause matching in Geometry.area/1
|
||||||
|
|
||||||
# Due to immutability, recursion is a big part of elixir
|
# Due to immutability, recursion is a big part of Elixir
|
||||||
defmodule Recursion do
|
defmodule Recursion do
|
||||||
def sum_list([head | tail], acc) do
|
def sum_list([head | tail], acc) do
|
||||||
sum_list(tail, acc + head)
|
sum_list(tail, acc + head)
|
||||||
@@ -382,7 +381,7 @@ end
|
|||||||
## ---------------------------
|
## ---------------------------
|
||||||
|
|
||||||
# Elixir relies on the actor model for concurrency. All we need to write
|
# Elixir relies on the actor model for concurrency. All we need to write
|
||||||
# concurrent programs in elixir are three primitives: spawning processes,
|
# concurrent programs in Elixir are three primitives: spawning processes,
|
||||||
# sending messages and receiving messages.
|
# sending messages and receiving messages.
|
||||||
|
|
||||||
# To start a new process we use the `spawn` function, which takes a function
|
# To start a new process we use the `spawn` function, which takes a function
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
language: elixir
|
language: Elixir
|
||||||
contributors:
|
contributors:
|
||||||
- ["Joao Marques", "http://github.com/mrshankly"]
|
- ["Joao Marques", "http://github.com/mrshankly"]
|
||||||
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
||||||
@@ -23,10 +23,10 @@ y otras características más.
|
|||||||
# No hay comentarios multilinea,
|
# No hay comentarios multilinea,
|
||||||
# pero se pueden apilar varios comentarios.
|
# pero se pueden apilar varios comentarios.
|
||||||
|
|
||||||
# Para usar el shell de elixir se usa el comando `iex`.
|
# Para usar el shell de Elixir se usa el comando `iex`.
|
||||||
# Los módulos se compilan con el comando `elixirc`.
|
# Los módulos se compilan con el comando `elixirc`.
|
||||||
|
|
||||||
# Ambos deberían estar en la ruta si elixir se instaló correctamente.
|
# Ambos deberían estar en la ruta si Elixir se instaló correctamente.
|
||||||
|
|
||||||
## ---------------------------
|
## ---------------------------
|
||||||
## -- Tipos básicos
|
## -- Tipos básicos
|
||||||
@@ -55,7 +55,7 @@ elem({1, 2, 3}, 0) #=> 1
|
|||||||
head #=> 1
|
head #=> 1
|
||||||
tail #=> [2,3]
|
tail #=> [2,3]
|
||||||
|
|
||||||
# En elixir, solo como Erlang, el `=` denota la coincidencia de patrones y
|
# En Elixir, solo como Erlang, el `=` denota la coincidencia de patrones y
|
||||||
# no una asignación.
|
# no una asignación.
|
||||||
#
|
#
|
||||||
# This is how the above example of accessing the head and tail of a list works.
|
# This is how the above example of accessing the head and tail of a list works.
|
||||||
@@ -87,7 +87,7 @@ string.
|
|||||||
<<?a, ?b, ?c>> #=> "abc"
|
<<?a, ?b, ?c>> #=> "abc"
|
||||||
[?a, ?b, ?c] #=> 'abc'
|
[?a, ?b, ?c] #=> 'abc'
|
||||||
|
|
||||||
# `?a` en elixir devuelve el valor ASCII para el caracter `a`
|
# `?a` en Elixir devuelve el valor ASCII para el caracter `a`
|
||||||
?a #=> 97
|
?a #=> 97
|
||||||
|
|
||||||
# Para concatenar listas se usa `++`, para binarios `<>`
|
# Para concatenar listas se usa `++`, para binarios `<>`
|
||||||
@@ -120,7 +120,7 @@ genders.gillian #=> "female"
|
|||||||
5 * 2 #=> 10
|
5 * 2 #=> 10
|
||||||
10 / 2 #=> 5.0
|
10 / 2 #=> 5.0
|
||||||
|
|
||||||
# En elixir el operador `/` siempre devuelve un número flotante
|
# En Elixir el operador `/` siempre devuelve un número flotante
|
||||||
|
|
||||||
# Para hacer la división de número entero se debe usar `div`
|
# Para hacer la división de número entero se debe usar `div`
|
||||||
div(10, 2) #=> 5
|
div(10, 2) #=> 5
|
||||||
@@ -175,7 +175,7 @@ else
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Se acuerda de la coincidencia de patrones?
|
# Se acuerda de la coincidencia de patrones?
|
||||||
# Muchas estructuras de control de flujo en elixir confían en ella.
|
# Muchas estructuras de control de flujo en Elixir confían en ella.
|
||||||
|
|
||||||
# `case` permite comparar un valor con muchos patrones:
|
# `case` permite comparar un valor con muchos patrones:
|
||||||
case {:one, :two} do
|
case {:one, :two} do
|
||||||
@@ -305,7 +305,7 @@ Geometry.area({:circle, 3}) #=> 28.25999999999999801048
|
|||||||
# Geometry.area({:circle, "not_a_number"})
|
# Geometry.area({:circle, "not_a_number"})
|
||||||
#=> ** (FunctionClauseError) no function clause matching in Geometry.area/1
|
#=> ** (FunctionClauseError) no function clause matching in Geometry.area/1
|
||||||
|
|
||||||
# Debido a la inmutabilidad, la recursión es una gran parte de elixir
|
# Debido a la inmutabilidad, la recursión es una gran parte de Elixir
|
||||||
defmodule Recursion do
|
defmodule Recursion do
|
||||||
def sum_list([head | tail], acc) do
|
def sum_list([head | tail], acc) do
|
||||||
sum_list(tail, acc + head)
|
sum_list(tail, acc + head)
|
||||||
@@ -380,7 +380,7 @@ end
|
|||||||
## ---------------------------
|
## ---------------------------
|
||||||
|
|
||||||
# Elixir confía en el modelo actor para la concurrencia. Todo lo que se necesita para escribir
|
# Elixir confía en el modelo actor para la concurrencia. Todo lo que se necesita para escribir
|
||||||
# programas concurrentes en elixir son tres primitivas: procesos de desove,
|
# programas concurrentes en Elixir son tres primitivas: procesos de desove,
|
||||||
# envío de mensajes y recepción de mensajes.
|
# envío de mensajes y recepción de mensajes.
|
||||||
|
|
||||||
# Para empezar un nuevo proceso se usa la función `spawn`,
|
# Para empezar un nuevo proceso se usa la función `spawn`,
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
language: elixir
|
language: Elixir
|
||||||
contributors:
|
contributors:
|
||||||
- ["Joao Marques", "http://github.com/mrshankly"]
|
- ["Joao Marques", "http://github.com/mrshankly"]
|
||||||
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
language: elixir
|
language: Elixir
|
||||||
contributors:
|
contributors:
|
||||||
- ["Luca 'Kino' Maroni", "https://github.com/kino90"]
|
- ["Luca 'Kino' Maroni", "https://github.com/kino90"]
|
||||||
- ["Joao Marques", "http://github.com/mrshankly"]
|
- ["Joao Marques", "http://github.com/mrshankly"]
|
||||||
@@ -21,11 +21,11 @@ e molte altre funzionalità.
|
|||||||
# Non esistono commenti multilinea,
|
# Non esistono commenti multilinea,
|
||||||
# ma puoi concatenare più commenti.
|
# ma puoi concatenare più commenti.
|
||||||
|
|
||||||
# Per usare la shell di elixir usa il comando `iex`.
|
# Per usare la shell di Elixir usa il comando `iex`.
|
||||||
# Compila i tuoi moduli con il comando `elixirc`.
|
# Compila i tuoi moduli con il comando `elixirc`.
|
||||||
|
|
||||||
# Entrambi i comandi dovrebbero già essere nel tuo PATH se hai installato
|
# Entrambi i comandi dovrebbero già essere nel tuo PATH se hai installato
|
||||||
# elixir correttamente.
|
# Elixir correttamente.
|
||||||
|
|
||||||
## ---------------------------
|
## ---------------------------
|
||||||
## -- Tipi di base
|
## -- Tipi di base
|
||||||
@@ -87,7 +87,7 @@ multi-linea.
|
|||||||
<<?a, ?b, ?c>> #=> "abc"
|
<<?a, ?b, ?c>> #=> "abc"
|
||||||
[?a, ?b, ?c] #=> 'abc'
|
[?a, ?b, ?c] #=> 'abc'
|
||||||
|
|
||||||
# `?a` in elixir restituisce il valore ASCII della lettera `a`
|
# `?a` in Elixir restituisce il valore ASCII della lettera `a`
|
||||||
?a #=> 97
|
?a #=> 97
|
||||||
|
|
||||||
# Per concatenare liste si usa `++`, per binari si usa `<>`
|
# Per concatenare liste si usa `++`, per binari si usa `<>`
|
||||||
@@ -112,7 +112,7 @@ minore..maggiore = 1..10 # Puoi fare pattern matching anche sugli intervalli
|
|||||||
5 * 2 #=> 10
|
5 * 2 #=> 10
|
||||||
10 / 2 #=> 5.0
|
10 / 2 #=> 5.0
|
||||||
|
|
||||||
# In elixir l'operatore `/` restituisce sempre un decimale.
|
# In Elixir l'operatore `/` restituisce sempre un decimale.
|
||||||
|
|
||||||
# Per fare una divisione intera si usa `div`
|
# Per fare una divisione intera si usa `div`
|
||||||
div(10, 2) #=> 5
|
div(10, 2) #=> 5
|
||||||
@@ -173,7 +173,7 @@ else
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Ti ricordi il pattern matching?
|
# Ti ricordi il pattern matching?
|
||||||
# Moltre strutture di controllo di flusso in elixir si basano su di esso.
|
# Moltre strutture di controllo di flusso in Elixir si basano su di esso.
|
||||||
|
|
||||||
# `case` ci permette di confrontare un valore a diversi pattern:
|
# `case` ci permette di confrontare un valore a diversi pattern:
|
||||||
case {:uno, :due} do
|
case {:uno, :due} do
|
||||||
@@ -307,7 +307,7 @@ Geometria.area({:cerchio, 3}) #=> 28.25999999999999801048
|
|||||||
# Geometria.area({:cerchio, "non_un_numero"})
|
# Geometria.area({:cerchio, "non_un_numero"})
|
||||||
#=> ** (FunctionClauseError) no function clause matching in Geometria.area/1
|
#=> ** (FunctionClauseError) no function clause matching in Geometria.area/1
|
||||||
|
|
||||||
# A causa dell'immutabilità dei dati, la ricorsione è molto frequente in elixir
|
# A causa dell'immutabilità dei dati, la ricorsione è molto frequente in Elixir
|
||||||
defmodule Ricorsione do
|
defmodule Ricorsione do
|
||||||
def somma_lista([testa | coda], accumulatore) do
|
def somma_lista([testa | coda], accumulatore) do
|
||||||
somma_lista(coda, accumulatore + testa)
|
somma_lista(coda, accumulatore + testa)
|
||||||
@@ -382,7 +382,7 @@ end
|
|||||||
## ---------------------------
|
## ---------------------------
|
||||||
|
|
||||||
# Elixir si basa sul modello degli attori per la concorrenza.
|
# Elixir si basa sul modello degli attori per la concorrenza.
|
||||||
# Tutto ciò di cui abbiamo bisogno per scrivere programmi concorrenti in elixir
|
# Tutto ciò di cui abbiamo bisogno per scrivere programmi concorrenti in Elixir
|
||||||
# sono tre primitive: creare processi, inviare messaggi e ricevere messaggi.
|
# sono tre primitive: creare processi, inviare messaggi e ricevere messaggi.
|
||||||
|
|
||||||
# Per creare un nuovo processo si usa la funzione `spawn`, che riceve una
|
# Per creare un nuovo processo si usa la funzione `spawn`, che riceve una
|
||||||
@@ -434,7 +434,7 @@ self() #=> #PID<0.27.0>
|
|||||||
|
|
||||||
## Referenze
|
## Referenze
|
||||||
|
|
||||||
* [Getting started guide](http://elixir-lang.org/getting_started/1.html) dalla [pagina web ufficiale di elixir](http://elixir-lang.org)
|
* [Getting started guide](http://elixir-lang.org/getting_started/1.html) dalla [pagina web ufficiale di Elixir](http://elixir-lang.org)
|
||||||
* [Documentazione Elixir](https://elixir-lang.org/docs.html)
|
* [Documentazione Elixir](https://elixir-lang.org/docs.html)
|
||||||
* ["Programming Elixir"](https://pragprog.com/book/elixir/programming-elixir) di Dave Thomas
|
* ["Programming Elixir"](https://pragprog.com/book/elixir/programming-elixir) di Dave Thomas
|
||||||
* [Elixir Cheat Sheet](http://media.pragprog.com/titles/elixir/ElixirCheat.pdf)
|
* [Elixir Cheat Sheet](http://media.pragprog.com/titles/elixir/ElixirCheat.pdf)
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
language: elixir
|
language: Elixir
|
||||||
contributors:
|
contributors:
|
||||||
- ["Joao Marques", "http://github.com/mrshankly"]
|
- ["Joao Marques", "http://github.com/mrshankly"]
|
||||||
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
||||||
@@ -20,7 +20,7 @@ e muitos outros recursos.
|
|||||||
# Não há comentários de múltiplas linhas,
|
# Não há comentários de múltiplas linhas,
|
||||||
# mas você pode empilhar os comentários.
|
# mas você pode empilhar os comentários.
|
||||||
|
|
||||||
# Para usar o shell do elixir use o comando `iex`.
|
# Para usar o shell do Elixir use o comando `iex`.
|
||||||
# Compile seus módulos com o comando `elixirc`.
|
# Compile seus módulos com o comando `elixirc`.
|
||||||
|
|
||||||
# Ambos devem estar em seu path se você instalou o Elixir corretamente.
|
# Ambos devem estar em seu path se você instalou o Elixir corretamente.
|
||||||
@@ -51,7 +51,7 @@ elem({1, 2, 3}, 0) #=> 1
|
|||||||
head #=> 1
|
head #=> 1
|
||||||
tail #=> [2,3]
|
tail #=> [2,3]
|
||||||
|
|
||||||
# Em elixir, bem como em Erlang, o sinal `=` denota pattern match,
|
# Em Elixir, bem como em Erlang, o sinal `=` denota pattern match,
|
||||||
# e não uma atribuição.
|
# e não uma atribuição.
|
||||||
#
|
#
|
||||||
# Isto significa que o que estiver à esquerda (pattern) é comparado com o que
|
# Isto significa que o que estiver à esquerda (pattern) é comparado com o que
|
||||||
@@ -85,7 +85,7 @@ linhas.
|
|||||||
<<?a, ?b, ?c>> #=> "abc"
|
<<?a, ?b, ?c>> #=> "abc"
|
||||||
[?a, ?b, ?c] #=> 'abc'
|
[?a, ?b, ?c] #=> 'abc'
|
||||||
|
|
||||||
# `?a` em elixir retorna o valor ASCII para a letra `a`
|
# `?a` em Elixir retorna o valor ASCII para a letra `a`
|
||||||
?a #=> 97
|
?a #=> 97
|
||||||
|
|
||||||
# Para concatenar listas use `++`, para binários use `<>`
|
# Para concatenar listas use `++`, para binários use `<>`
|
||||||
@@ -110,7 +110,7 @@ menor..maior = 1..10 # Pattern matching pode ser usada em ranges também
|
|||||||
5 * 2 #=> 10
|
5 * 2 #=> 10
|
||||||
10 / 2 #=> 5.0
|
10 / 2 #=> 5.0
|
||||||
|
|
||||||
# Em elixir o operador `/` sempre retorna um float.
|
# Em Elixir o operador `/` sempre retorna um float.
|
||||||
|
|
||||||
# Para divisão de inteiros use `div`
|
# Para divisão de inteiros use `div`
|
||||||
div(10, 2) #=> 5
|
div(10, 2) #=> 5
|
||||||
@@ -167,7 +167,7 @@ else
|
|||||||
"Isso será"
|
"Isso será"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Lembra do patter matching? Muitas estruturas de fluxo de controle em elixir contam com ela.
|
# Lembra do patter matching? Muitas estruturas de fluxo de controle em Elixir contam com ela.
|
||||||
|
|
||||||
# `case` nos permite comparar um valor com muitos patterns:
|
# `case` nos permite comparar um valor com muitos patterns:
|
||||||
case {:um, :dois} do
|
case {:um, :dois} do
|
||||||
@@ -296,7 +296,7 @@ Geometry.area({:circle, 3}) #=> 28.25999999999999801048
|
|||||||
# Geometry.area({:circle, "not_a_number"})
|
# Geometry.area({:circle, "not_a_number"})
|
||||||
#=> ** (FunctionClauseError) no function clause matching in Geometry.area/1
|
#=> ** (FunctionClauseError) no function clause matching in Geometry.area/1
|
||||||
|
|
||||||
# Devido à imutabilidade, recursão é uma grande parte do elixir
|
# Devido à imutabilidade, recursão é uma grande parte do Elixir
|
||||||
defmodule Recursion do
|
defmodule Recursion do
|
||||||
def sum_list([head | tail], acc) do
|
def sum_list([head | tail], acc) do
|
||||||
sum_list(tail, acc + head)
|
sum_list(tail, acc + head)
|
||||||
@@ -309,7 +309,7 @@ end
|
|||||||
|
|
||||||
Recursion.sum_list([1,2,3], 0) #=> 6
|
Recursion.sum_list([1,2,3], 0) #=> 6
|
||||||
|
|
||||||
# Módulos do elixir suportam atributos, hpa atributos embutidos e você
|
# Módulos do Elixir suportam atributos, hpa atributos embutidos e você
|
||||||
# pode também adicionar os seus próprios.
|
# pode também adicionar os seus próprios.
|
||||||
defmodule MyMod do
|
defmodule MyMod do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
@@ -361,7 +361,7 @@ end
|
|||||||
## ---------------------------
|
## ---------------------------
|
||||||
|
|
||||||
# Elixir conta com o modelo de ator para concorrência. Tudo o que precisamos para
|
# Elixir conta com o modelo de ator para concorrência. Tudo o que precisamos para
|
||||||
# escrever programas concorrentes em elixir são três primitivos: spawning processes,
|
# escrever programas concorrentes em Elixir são três primitivos: spawning processes,
|
||||||
# sending messages e receiving messages.
|
# sending messages e receiving messages.
|
||||||
|
|
||||||
# Para iniciar um novo processo usamos a função `spawn`, a qual leva uma função
|
# Para iniciar um novo processo usamos a função `spawn`, a qual leva uma função
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
language: elixir
|
language: Elixir
|
||||||
contributors:
|
contributors:
|
||||||
- ["Joao Marques", "http://github.com/mrshankly"]
|
- ["Joao Marques", "http://github.com/mrshankly"]
|
||||||
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
||||||
@@ -22,7 +22,7 @@ posibilități.
|
|||||||
# Pentru comentarii pe mai multe linii nu există sintaxă separată,
|
# Pentru comentarii pe mai multe linii nu există sintaxă separată,
|
||||||
# de aceea folosiți mai multe linii cu comentarii.
|
# de aceea folosiți mai multe linii cu comentarii.
|
||||||
|
|
||||||
# Pentru a folosi shell-ul elixir utilizați comanda `iex`.
|
# Pentru a folosi shell-ul Elixir utilizați comanda `iex`.
|
||||||
# Compilați modulele cu comanda `elixirc`.
|
# Compilați modulele cu comanda `elixirc`.
|
||||||
|
|
||||||
# Ambele comenzi vor lucra în terminal, dacă ați instalat Elixir corect.
|
# Ambele comenzi vor lucra în terminal, dacă ați instalat Elixir corect.
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
language: elixir
|
language: Elixir
|
||||||
contributors:
|
contributors:
|
||||||
- ["Joao Marques", "http://github.com/mrshankly"]
|
- ["Joao Marques", "http://github.com/mrshankly"]
|
||||||
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
language: elixir
|
language: Elixir
|
||||||
contributors:
|
contributors:
|
||||||
- ["Joao Marques", "http://github.com/mrshankly"]
|
- ["Joao Marques", "http://github.com/mrshankly"]
|
||||||
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
||||||
@@ -24,7 +24,7 @@ a množstvo funkcií.
|
|||||||
# Pre spustenie Elixir shellu zadajte príkaz `iex`
|
# Pre spustenie Elixir shellu zadajte príkaz `iex`
|
||||||
# Kompiláciu zdrojových kódov vykonáte príkazom `elixirc`
|
# Kompiláciu zdrojových kódov vykonáte príkazom `elixirc`
|
||||||
|
|
||||||
# Obe príkazy by sa už mali nachádzať v path pokiaľ ste nainštalovali elixir
|
# Obe príkazy by sa už mali nachádzať v path pokiaľ ste nainštalovali Elixir
|
||||||
# správne.
|
# správne.
|
||||||
|
|
||||||
## ---------------------------
|
## ---------------------------
|
||||||
@@ -86,7 +86,7 @@ reťazec.
|
|||||||
<<?a, ?b, ?c>> #=> "abc"
|
<<?a, ?b, ?c>> #=> "abc"
|
||||||
[?a, ?b, ?c] #=> 'abc'
|
[?a, ?b, ?c] #=> 'abc'
|
||||||
|
|
||||||
# `?a` v elixire vráti ASCII číselnú reprezentáciu pre znak `a`
|
# `?a` v Elixir vráti ASCII číselnú reprezentáciu pre znak `a`
|
||||||
?a #=> 97
|
?a #=> 97
|
||||||
|
|
||||||
# Pre spájanie zoznamov sa používa `++`, pre binárne typy `<>`
|
# Pre spájanie zoznamov sa používa `++`, pre binárne typy `<>`
|
||||||
@@ -119,7 +119,7 @@ pohlavia.gillian #=> "žena"
|
|||||||
5 * 2 #=> 10
|
5 * 2 #=> 10
|
||||||
10 / 2 #=> 5.0
|
10 / 2 #=> 5.0
|
||||||
|
|
||||||
# V elixire operátor `/` vždy vráti float (reálne číslo).
|
# V Elixir operátor `/` vždy vráti float (reálne číslo).
|
||||||
|
|
||||||
# Pre celočíselné delenie sa používa `div`
|
# Pre celočíselné delenie sa používa `div`
|
||||||
div(10, 2) #=> 5
|
div(10, 2) #=> 5
|
||||||
@@ -182,7 +182,7 @@ else
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Pamätáte sa na pattern matching? Mnoho štruktúr pre riadenie toku v
|
# Pamätáte sa na pattern matching? Mnoho štruktúr pre riadenie toku v
|
||||||
# elixire sa spoliehajú práve na pattern matching.
|
# Elixir sa spoliehajú práve na pattern matching.
|
||||||
|
|
||||||
# `case` dovolí nám porovnať hodnotu oproti mnohým vzorom:
|
# `case` dovolí nám porovnať hodnotu oproti mnohým vzorom:
|
||||||
case {:one, :two} do
|
case {:one, :two} do
|
||||||
@@ -314,7 +314,7 @@ Geometria.oblast({:kruh, 3}) #=> 28.25999999999999801048
|
|||||||
# Geometria.oblast({:kruh, "nie_je_cislo"})
|
# Geometria.oblast({:kruh, "nie_je_cislo"})
|
||||||
#=> ** (FunctionClauseError) no function clause matching in Geometria.oblast/1
|
#=> ** (FunctionClauseError) no function clause matching in Geometria.oblast/1
|
||||||
|
|
||||||
# Vďaka nemeniteľnosti (immutability) je rekurzia významnou časťou elixiru
|
# Vďaka nemeniteľnosti (immutability) je rekurzia významnou časťou Elixir
|
||||||
defmodule Rekurzia do
|
defmodule Rekurzia do
|
||||||
def sumuj_zoznam([hlavicka | schvost], acc) do
|
def sumuj_zoznam([hlavicka | schvost], acc) do
|
||||||
sumuj_zoznam(chvost, acc + hlavicka)
|
sumuj_zoznam(chvost, acc + hlavicka)
|
||||||
@@ -389,7 +389,7 @@ end
|
|||||||
## ---------------------------
|
## ---------------------------
|
||||||
|
|
||||||
# Elixir sa pri konkurencii spolieha na Actor model. Všetko čo je
|
# Elixir sa pri konkurencii spolieha na Actor model. Všetko čo je
|
||||||
# potrebné na písanie konkuretných programov v elixire sú tri primitívy:
|
# potrebné na písanie konkuretných programov v Elixir sú tri primitívy:
|
||||||
# spawning procesy, posielanie a prijímanie správ.
|
# spawning procesy, posielanie a prijímanie správ.
|
||||||
|
|
||||||
# Na spustnenie nového procesu použijeme `spawn` funkciu, ktorá má ako
|
# Na spustnenie nového procesu použijeme `spawn` funkciu, ktorá má ako
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
language: elixir
|
language: Elixir
|
||||||
contributors:
|
contributors:
|
||||||
- ["Joao Marques", "http://github.com/mrshankly"]
|
- ["Joao Marques", "http://github.com/mrshankly"]
|
||||||
translators:
|
translators:
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
language: elixir
|
language: Elixir
|
||||||
contributors:
|
contributors:
|
||||||
- ["Joao Marques", "http://github.com/mrshankly"]
|
- ["Joao Marques", "http://github.com/mrshankly"]
|
||||||
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
- ["Dzianis Dashkevich", "https://github.com/dskecse"]
|
||||||
@@ -19,10 +19,10 @@ Elixir 是一門建構在 Erlang 虛擬機上的現代函數式語言。它完
|
|||||||
# 沒有多行註解的功能
|
# 沒有多行註解的功能
|
||||||
# 但你可以連續使用多個單行
|
# 但你可以連續使用多個單行
|
||||||
|
|
||||||
# 用 `iex` 來進入 elixir shell
|
# 用 `iex` 來進入 Elixir shell
|
||||||
# 用 `elixirc` 來編譯你的模組
|
# 用 `elixirc` 來編譯你的模組
|
||||||
|
|
||||||
# 如果你已成功安裝 elixir 的話,這兩個命令應已在你的 path 下。
|
# 如果你已成功安裝 Elixir 的話,這兩個命令應已在你的 path 下。
|
||||||
|
|
||||||
## ---------------------------
|
## ---------------------------
|
||||||
## -- 基本型別
|
## -- 基本型別
|
||||||
@@ -50,7 +50,7 @@ elem({1, 2, 3}, 0) #=> 1
|
|||||||
head #=> 1
|
head #=> 1
|
||||||
tail #=> [2,3]
|
tail #=> [2,3]
|
||||||
|
|
||||||
# 在 elixir 中,就如同 Erlang 裡一樣,`=` 代表的是模式比對,而非指派。
|
# 在 Elixir 中,就如同 Erlang 裡一樣,`=` 代表的是模式比對,而非指派。
|
||||||
#
|
#
|
||||||
# 這代表將使用左手邊的模式 (pattern) 去與右手邊的值進行比對。
|
# 這代表將使用左手邊的模式 (pattern) 去與右手邊的值進行比對。
|
||||||
#
|
#
|
||||||
@@ -80,7 +80,7 @@ string.
|
|||||||
<<?a, ?b, ?c>> #=> "abc"
|
<<?a, ?b, ?c>> #=> "abc"
|
||||||
[?a, ?b, ?c] #=> 'abc'
|
[?a, ?b, ?c] #=> 'abc'
|
||||||
|
|
||||||
# `?a` 在 elixir 中會回傳字母 `a` 的 ASCII 整數
|
# `?a` 在 Elixir 中會回傳字母 `a` 的 ASCII 整數
|
||||||
?a #=> 97
|
?a #=> 97
|
||||||
|
|
||||||
# 用 `++` 來合併串列,而合併二進位則要用 `<>`
|
# 用 `++` 來合併串列,而合併二進位則要用 `<>`
|
||||||
@@ -105,7 +105,7 @@ lower..upper = 1..10 # 可以對 range 進行模式比對
|
|||||||
5 * 2 #=> 10
|
5 * 2 #=> 10
|
||||||
10 / 2 #=> 5.0
|
10 / 2 #=> 5.0
|
||||||
|
|
||||||
# 在 elixir 中, `/` 運算元永遠回傳浮點數。
|
# 在 Elixir 中, `/` 運算元永遠回傳浮點數。
|
||||||
|
|
||||||
# 若需要回傳整數的除法,用 `div`
|
# 若需要回傳整數的除法,用 `div`
|
||||||
div(10, 2) #=> 5
|
div(10, 2) #=> 5
|
||||||
@@ -290,7 +290,7 @@ Geometry.area({:circle, 3}) #=> 28.25999999999999801048
|
|||||||
# Geometry.area({:circle, "not_a_number"})
|
# Geometry.area({:circle, "not_a_number"})
|
||||||
#=> ** (FunctionClauseError) no function clause matching in Geometry.area/1
|
#=> ** (FunctionClauseError) no function clause matching in Geometry.area/1
|
||||||
|
|
||||||
# 由於不可變特性 (immutability),遞迴在 elixir 中扮演重要的角色。
|
# 由於不可變特性 (immutability),遞迴在 Elixir 中扮演重要的角色。
|
||||||
defmodule Recursion do
|
defmodule Recursion do
|
||||||
def sum_list([head | tail], acc) do
|
def sum_list([head | tail], acc) do
|
||||||
sum_list(tail, acc + head)
|
sum_list(tail, acc + head)
|
||||||
@@ -356,7 +356,7 @@ end
|
|||||||
## -- 平行處理
|
## -- 平行處理
|
||||||
## ---------------------------
|
## ---------------------------
|
||||||
|
|
||||||
# Elixir 依靠 actor 模式來進行平行處理。在 elixir 中要寫出平行處理程式,
|
# Elixir 依靠 actor 模式來進行平行處理。在 Elixir 中要寫出平行處理程式,
|
||||||
# 只需要三個基本要素:建立行程,發送訊息及接收訊息。
|
# 只需要三個基本要素:建立行程,發送訊息及接收訊息。
|
||||||
|
|
||||||
# 我們用 `spawn` 函式來建立行程,它接收一個函式當參數。
|
# 我們用 `spawn` 函式來建立行程,它接收一個函式當參數。
|
||||||
|
Reference in New Issue
Block a user