diff --git a/_posts/2012-04-24-a-peek-inside-elixir-s-parallel-compiler.markdown b/_posts/2012-04-24-a-peek-inside-elixir-s-parallel-compiler.markdown index 06a1c6e19..05d678a0e 100644 --- a/_posts/2012-04-24-a-peek-inside-elixir-s-parallel-compiler.markdown +++ b/_posts/2012-04-24-a-peek-inside-elixir-s-parallel-compiler.markdown @@ -14,7 +14,7 @@ The idea of the parallel compiler is very simple: for each file we want to compi In Elixir, we could write this code as follows: - def spawn_compilers([current|files], output) do + def spawn_compilers([current | files], output) do parent = Process.self() child = spawn_link(fn -> :elixir_compiler.file_to_path(current, output) @@ -32,7 +32,7 @@ In Elixir, we could write this code as follows: :done end -In the first line, we define a function named `spawn_compilers` that receives two arguments, the first is a list of files to compile and the second is a string telling us where to write the compiled file. The first argument is represented as a list with head and tail (`[current|files]`) where the top of the list is assigned to `current` and the remaining items to `files`. If the list is empty, the first clause of `spawn_compilers` is not going to match, the clause `spawn_compilers([], _output)` defined at the end will instead. +In the first line, we define a function named `spawn_compilers` that receives two arguments, the first is a list of files to compile and the second is a string telling us where to write the compiled file. The first argument is represented as a list with head and tail (`[current | files]`) where the top of the list is assigned to `current` and the remaining items to `files`. If the list is empty, the first clause of `spawn_compilers` is not going to match, the clause `spawn_compilers([], _output)` defined at the end will instead. Inside `spawn_compilers`, we first retrieve the PID of the current process with `Process.self` (remember we are talking about Erlang processes/actors and not OS processes) and then proceed to spawn a new process to execute the given function in parallel. Spawning a new process is done with the `spawn_link` function. @@ -121,13 +121,13 @@ Notice that we have two small additions. First we store the `:elixir_parent_comp Second, our main process can now receive a new `{ :waiting, child, module }` message, so we need to extend it to account for those messages. Not only that, we need to control which PIDs we have spawned so we can notify them whenever a new module is compiled, forcing us to add a new argument to the `spawn_compilers` function. `spawn_compilers` would then be rewritten as follows: - def spawn_compilers([current|files], output, stack) do + def spawn_compilers([current | files], output, stack) do parent = Process.self() child = spawn_link(fn -> :elixir_compiler.file_to_path(current, output) send parent, { :compiled, Process.self() } end) - wait_for_messages(files, output, [child|stack]) + wait_for_messages(files, output, [child | stack]) end # No more files and stack is empty, we are done diff --git a/_posts/2013-05-23-elixir-v0-9-0-released.markdown b/_posts/2013-05-23-elixir-v0-9-0-released.markdown index d4b4861c0..0389135f6 100644 --- a/_posts/2013-05-23-elixir-v0-9-0-released.markdown +++ b/_posts/2013-05-23-elixir-v0-9-0-released.markdown @@ -77,7 +77,7 @@ defimpl Enumerable, for: List do do_reduce(list, acc, fun) end - defp do_reduce([h|t], acc, fun) do + defp do_reduce([h | t], acc, fun) do do_reduce(t, fun.(h, acc), fun) end @@ -101,7 +101,7 @@ The `Enum.map/2` we have used above is now implemented in terms of this reducing defmodule Enum do def map(collection, fun) do Enumerable.reduce(collection, [], fn(x, acc) -> - [fun.(x, acc)|acc] + [fun.(x, acc) | acc] end) |> reverse end end diff --git a/_posts/2013-12-11-elixir-s-new-continuable-enumerators.markdown b/_posts/2013-12-11-elixir-s-new-continuable-enumerators.markdown index f3e93f664..9a0670d9f 100644 --- a/_posts/2013-12-11-elixir-s-new-continuable-enumerators.markdown +++ b/_posts/2013-12-11-elixir-s-new-continuable-enumerators.markdown @@ -152,7 +152,7 @@ function. ```elixir defmodule Interleave do def interleave(a, b) do - step = fn x, acc -> { :suspend, [x|acc] } end + step = fn x, acc -> { :suspend, [x | acc] } end af = &Enumerable.reduce(a, &1, step) bf = &Enumerable.reduce(b, &1, step) do_interleave(af, bf, []) |> :lists.reverse() diff --git a/crash-course.markdown b/crash-course.markdown index 3872184c6..553f92084 100644 --- a/crash-course.markdown +++ b/crash-course.markdown @@ -461,7 +461,7 @@ Pattern matching in Elixir is based on Erlang's implementation and in general is **Erlang** ```erlang -loop_through([H|T]) -> +loop_through([H | T]) -> io:format('~p~n', [H]), loop_through(T); @@ -472,7 +472,7 @@ loop_through([]) -> **Elixir** ```elixir -def loop_through([h|t]) do +def loop_through([h | t]) do IO.inspect h loop_through t end diff --git a/getting-started/basic-types.markdown b/getting-started/basic-types.markdown index 2e825d324..d699feafc 100644 --- a/getting-started/basic-types.markdown +++ b/getting-started/basic-types.markdown @@ -348,7 +348,7 @@ What is the difference between lists and tuples? Lists are stored in memory as linked lists, meaning that each element in a list holds its value and points to the following element until the end of the list is reached. We call each pair of value and pointer a **cons cell**: ```iex -iex> list = [1|[2|[3|[]]]] +iex> list = [1 | [2 | [3 | []]]] [1, 2, 3] ``` diff --git a/getting-started/meta/domain-specific-languages.markdown b/getting-started/meta/domain-specific-languages.markdown index 849aeb423..66c714bbc 100644 --- a/getting-started/meta/domain-specific-languages.markdown +++ b/getting-started/meta/domain-specific-languages.markdown @@ -165,7 +165,7 @@ defmodule TestCase do function_name = String.to_atom("test " <> description) quote do # Prepend the newly defined test to the list of tests - @tests [unquote(function_name)|@tests] + @tests [unquote(function_name) | @tests] def unquote(function_name)(), do: unquote(block) end end diff --git a/getting-started/mix-otp/agent.markdown b/getting-started/mix-otp/agent.markdown index 4e984377f..478fabdb2 100644 --- a/getting-started/mix-otp/agent.markdown +++ b/getting-started/mix-otp/agent.markdown @@ -40,7 +40,7 @@ And play a bit with agents: ```iex iex> {:ok, agent} = Agent.start_link fn -> [] end {:ok, #PID<0.57.0>} -iex> Agent.update(agent, fn list -> ["eggs"|list] end) +iex> Agent.update(agent, fn list -> ["eggs" | list] end) :ok iex> Agent.get(agent, fn list -> list end) ["eggs"] diff --git a/getting-started/pattern-matching.markdown b/getting-started/pattern-matching.markdown index bf7969525..8113d872a 100644 --- a/getting-started/pattern-matching.markdown +++ b/getting-started/pattern-matching.markdown @@ -102,7 +102,7 @@ iex> tail Similar to the `hd/1` and `tl/1` functions, we can't match an empty list with a head and tail pattern: ```iex -iex> [h|t] = [] +iex> [h | t] = [] ** (MatchError) no match of right hand side value: [] ``` @@ -111,7 +111,7 @@ The `[head | tail]` format is not only used on pattern matching but also for pre ```iex iex> list = [1, 2, 3] [1, 2, 3] -iex> [0|list] +iex> [0 | list] [0, 1, 2, 3] ``` @@ -162,7 +162,7 @@ iex> {x, x} = {1, 2} In some cases, you don't care about a particular value in a pattern. It is a common practice to bind those values to the underscore, `_`. For example, if only the head of the list matters to us, we can assign the tail to underscore: ```iex -iex> [h|_] = [1, 2, 3] +iex> [h | _] = [1, 2, 3] [1, 2, 3] iex> h 1 diff --git a/getting-started/recursion.markdown b/getting-started/recursion.markdown index a4eccf56f..103411020 100644 --- a/getting-started/recursion.markdown +++ b/getting-started/recursion.markdown @@ -56,7 +56,7 @@ Let's now see how we can use the power of recursion to sum a list of numbers: ```elixir defmodule Math do - def sum_list([head|tail], accumulator) do + def sum_list([head | tail], accumulator) do sum_list(tail, head + accumulator) end @@ -68,9 +68,9 @@ end IO.puts Math.sum_list([1, 2, 3], 0) #=> 6 ``` -We invoke `sum_list` with the list `[1, 2, 3]` and the initial value `0` as arguments. We will try each clause until we find one that matches according to the pattern matching rules. In this case, the list `[1, 2, 3]` matches against `[head|tail]` which binds `head` to `1` and `tail` to `[2, 3]`; `accumulator` is set to `0`. +We invoke `sum_list` with the list `[1, 2, 3]` and the initial value `0` as arguments. We will try each clause until we find one that matches according to the pattern matching rules. In this case, the list `[1, 2, 3]` matches against `[head | tail]` which binds `head` to `1` and `tail` to `[2, 3]`; `accumulator` is set to `0`. -Then, we add the head of the list to the accumulator `head + accumulator` and call `sum_list` again, recursively, passing the tail of the list as its first argument. The tail will once again match `[head|tail]` until the list is empty, as seen below: +Then, we add the head of the list to the accumulator `head + accumulator` and call `sum_list` again, recursively, passing the tail of the list as its first argument. The tail will once again match `[head | tail]` until the list is empty, as seen below: ```elixir sum_list [1, 2, 3], 0 @@ -87,8 +87,8 @@ What if we instead want to double all of the values in our list? ```elixir defmodule Math do - def double_each([head|tail]) do - [head * 2|double_each(tail)] + def double_each([head | tail]) do + [head * 2 | double_each(tail)] end def double_each([]) do