You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: getting-started/alias-require-and-import.markdown
+2-2
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ end
40
40
41
41
The original `List` can still be accessed within `Stats` by the fully-qualified name `Elixir.List`.
42
42
43
-
> Note: All modules defined in Elixir are defined inside a main `Elixir` namespace. However, for convenience, you can omit "Elixir." when referencing them.
43
+
> Note: All modules defined in Elixir are defined inside the main `Elixir` namespace. However, for convenience, you can omit "Elixir." when referencing them.
44
44
45
45
Aliases are frequently used to define shortcuts. In fact, calling `alias` without an `:as` option sets the alias automatically to the last part of the module name, for example:
46
46
@@ -222,4 +222,4 @@ From Elixir v1.2, it is possible to alias, import or require multiple modules at
222
222
aliasMyApp.{Foo, Bar, Baz}
223
223
```
224
224
225
-
With this we have finished our tour of Elixir modules. The last topic to cover is module attributes.
225
+
With this, we have finished our tour of Elixir modules. The last topic to cover is module attributes.
Copy file name to clipboardExpand all lines: getting-started/basic-types.markdown
+2-2
Original file line number
Diff line number
Diff line change
@@ -66,7 +66,7 @@ iex> 1.0e-10
66
66
1.0e-10
67
67
```
68
68
69
-
Floats in Elixir are 64bit double precision.
69
+
Floats in Elixir are 64-bit double precision.
70
70
71
71
You can invoke the `round` function to get the closest integer to a given float, or the `trunc` function to get the integer part of a float.
72
72
@@ -385,6 +385,6 @@ iex> elem(tuple, 1)
385
385
386
386
When counting the elements in a data structure, Elixir also abides by a simple rule: the function is named `size` if the operation is in constant time (i.e. the value is pre-calculated) or `length` if the operation is linear (i.e. calculating the length gets slower as the input grows). As a mnemonic, both "length" and "linear" start with "l".
387
387
388
-
For example, we have used 4 counting functions so far: `byte_size/1` (for the number of bytes in a string), `tuple_size/1` (for tuple size), `length/1` (for list length) and `String.length/1` (for the number of graphemes in a string). We use `byte_size` to get the number of bytes in a string -- a cheap operation. Retrieving the number of unicode characters, on the other hand, uses `String.length`, and may be expensive as it relies on a traversal of the entire string.
388
+
For example, we have used 4 counting functions so far: `byte_size/1` (for the number of bytes in a string), `tuple_size/1` (for tuple size), `length/1` (for list length) and `String.length/1` (for the number of graphemes in a string). We use `byte_size` to get the number of bytes in a string -- a cheap operation. Retrieving the number of Unicode characters, on the other hand, uses `String.length`, and may be expensive as it relies on a traversal of the entire string.
389
389
390
390
Elixir also provides `Port`, `Reference`, and `PID` as data types (usually used in process communication), and we will take a quick look at them when talking about processes. For now, let's take a look at some of the basic operators that go with our basic types.
Copy file name to clipboardExpand all lines: getting-started/case-cond-and-if.markdown
+1-1
Original file line number
Diff line number
Diff line change
@@ -179,7 +179,7 @@ iex> if true, do: 1 + 2
179
179
3
180
180
```
181
181
182
-
Notice how the example above has a comma between `true` and `do:`, that's because it is using Elixir's regular syntax where each argument is separated by comma. We say this syntax is using *keyword lists*. We can pass `else` using keywords too:
182
+
Notice how the example above has a comma between `true` and `do:`, that's because it is using Elixir's regular syntax where each argument is separated by a comma. We say this syntax is using *keyword lists*. We can pass `else` using keywords too:
Copy file name to clipboardExpand all lines: getting-started/comprehensions.markdown
+3-3
Original file line number
Diff line number
Diff line change
@@ -16,11 +16,11 @@ iex> for n <- [1, 2, 3, 4], do: n * n
16
16
[1, 4, 9, 16]
17
17
```
18
18
19
-
A comprehension is made of three parts: generators, filters and collectables.
19
+
A comprehension is made of three parts: generators, filters, and collectables.
20
20
21
21
## Generators and filters
22
22
23
-
In the expression above, `n <- [1, 2, 3, 4]` is the **generator**. It is literally generating values to be used in the comprehension. Any enumerable can be passed in the right-hand side of the generator expression:
23
+
In the expression above, `n <- [1, 2, 3, 4]` is the **generator**. It is literally generating values to be used in the comprehension. Any enumerable can be passed on the right-hand side of the generator expression:
24
24
25
25
```iex
26
26
iex> for n <- 1..4, do: n * n
@@ -135,7 +135,7 @@ iex> for <<c <- " hello world ">>, c != ?\s, into: "", do: <<c>>
135
135
"helloworld"
136
136
```
137
137
138
-
Sets, maps and other dictionaries can also be given to the `:into` option. In general, `:into` accepts any structure that implements the `Collectable` protocol.
138
+
Sets, maps, and other dictionaries can also be given to the `:into` option. In general, `:into` accepts any structure that implements the `Collectable` protocol.
139
139
140
140
A common use case of `:into` can be transforming values in a map, without touching the keys:
Copy file name to clipboardExpand all lines: getting-started/enumerables-and-streams.markdown
+1-1
Original file line number
Diff line number
Diff line change
@@ -121,4 +121,4 @@ The example above will fetch the first 10 lines of the file you have selected. T
121
121
122
122
The amount of functionality in the [`Enum`](https://hexdocs.pm/elixir/Enum.html) and [`Stream`](https://hexdocs.pm/elixir/Stream.html) modules can be daunting at first, but you will get familiar with them case by case. In particular, focus on the `Enum` module first and only move to `Stream` for the particular scenarios where laziness is required, to either deal with slow resources or large, possibly infinite, collections.
123
123
124
-
Next we'll look at a feature central to Elixir, Processes, which allows us to write concurrent, parallel and distributed programs in an easy and understandable way.
124
+
Next, we'll look at a feature central to Elixir, Processes, which allows us to write concurrent, parallel and distributed programs in an easy and understandable way.
In this tutorial we are going to teach you the Elixir foundation, the language syntax, how to define modules, how to manipulate the characteristics of common data structures, and more. This chapter will focus on ensuring Elixir is installed and that you can successfully run Elixir's Interactive Shell, called IEx.
13
+
In this tutorial, we are going to teach you the Elixir foundation, the language syntax, how to define modules, how to manipulate the characteristics of common data structures, and more. This chapter will focus on ensuring Elixir is installed and that you can successfully run Elixir's Interactive Shell, called IEx.
Copy file name to clipboardExpand all lines: getting-started/io-and-the-file-system.markdown
+5-5
Original file line number
Diff line number
Diff line change
@@ -98,7 +98,7 @@ iex> Path.expand("~/hello")
98
98
99
99
Using functions from the `Path` module as opposed to directly manipulating strings is preferred since the `Path` module takes care of different operating systems transparently. Finally, keep in mind that Elixir will automatically convert slashes (`/`) into backslashes (`\`) on Windows when performing file operations.
100
100
101
-
With this we have covered the main modules that Elixir provides for dealing with IO and interacting with the file system. In the next sections, we will discuss some advanced topics regarding IO. Those sections are not necessary in order to write Elixir code, so feel free to skip them, but they do provide a nice overview of how the IO system is implemented in the <abbrtitle="Virtual Machine">VM</abbr> and other curiosities.
101
+
With this, we have covered the main modules that Elixir provides for dealing with IO and interacting with the file system. In the next sections, we will discuss some advanced topics regarding IO. Those sections are not necessary in order to write Elixir code, so feel free to skip them, but they do provide a nice overview of how the IO system is implemented in the <abbrtitle="Virtual Machine">VM</abbr> and other curiosities.
102
102
103
103
## Processes and group leaders
104
104
@@ -133,7 +133,7 @@ iex> IO.read(pid, 2)
133
133
"he"
134
134
```
135
135
136
-
By modelling IO devices with processes, the Erlang <abbrtitle="Virtual Machine">VM</abbr> allows different nodes in the same network to exchange file processes in order to read/write files in between nodes. Of all IO devices, there is one that is special to each process: the **group leader**.
136
+
By modeling IO devices with processes, the Erlang <abbrtitle="Virtual Machine">VM</abbr> allows different nodes in the same network to exchange file processes in order to read/write files in between nodes. Of all IO devices, there is one that is special to each process: the **group leader**.
137
137
138
138
When you write to `:stdio`, you are actually sending a message to the group leader, which writes to the standard-output file descriptor:
139
139
@@ -150,9 +150,9 @@ The group leader can be configured per process and is used in different situatio
150
150
151
151
## `iodata` and `chardata`
152
152
153
-
In all of the examples above, we used binaries when writing to files. In the chapter ["Binaries, strings and char lists"](/getting-started/binaries-strings-and-char-lists.html), we mentioned how strings are made of bytes while char lists are lists with unicode codepoints.
153
+
In all of the examples above, we used binaries when writing to files. In the chapter ["Binaries, strings and char lists"](/getting-started/binaries-strings-and-char-lists.html), we mentioned how strings are made of bytes while char lists are lists with Unicode codepoints.
154
154
155
-
The functions in `IO` and `File` also allow lists to be given as arguments. Not only that, they also allow a mixed list of lists, integers and binaries to be given:
155
+
The functions in `IO` and `File` also allow lists to be given as arguments. Not only that, they also allow a mixed list of lists, integers, and binaries to be given:
156
156
157
157
```iex
158
158
iex> IO.puts 'hello world'
@@ -163,7 +163,7 @@ hello world
163
163
:ok
164
164
```
165
165
166
-
However, using list in IO operations requires some attention. A list may represent either a bunch of bytes or a bunch of characters and which one to use depends on the encoding of the IO device. If the file is opened without encoding, the file is expected to be in raw mode, and the functions in the `IO` module starting with `bin*` must be used. Those functions expect an `iodata` as argument; i.e., they expect a list of integers representing bytes and binaries to be given.
166
+
However, using lists in IO operations requires some attention. A list may represent either a bunch of bytes or a bunch of characters and which one to use depends on the encoding of the IO device. If the file is opened without encoding, the file is expected to be in raw mode, and the functions in the `IO` module starting with `bin*` must be used. Those functions expect an `iodata` as an argument; i.e., they expect a list of integers representing bytes and binaries to be given.
167
167
168
168
On the other hand, `:stdio` and files opened with `:utf8` encoding work with the remaining functions in the `IO` module. Those functions expect a `char_data` as an argument, that is, a list of characters or strings.
Copy file name to clipboardExpand all lines: getting-started/meta/domain-specific-languages.markdown
+3-3
Original file line number
Diff line number
Diff line change
@@ -39,9 +39,9 @@ Of all the approaches above, the first is definitely the most flexible. If our d
39
39
40
40
The second approach uses function calls which better suits more complex APIs (for example, if you need to pass many options) and reads nicely in Elixir thanks to the pipe operator.
41
41
42
-
The third approach, uses macros, and is by far the most complex. It will take more lines of code to implement, it is hard and expensive to test (compared to testing simple functions), and it limits how the user may use the library since all validations need to be defined inside a module.
42
+
The third approach uses macros, and is by far the most complex. It will take more lines of code to implement, it is hard and expensive to test (compared to testing simple functions), and it limits how the user may use the library since all validations need to be defined inside a module.
43
43
44
-
To drive the point home, imagine you want to validate a certain attribute only if a given condition is met. We could easily achieve it with the first solution, by manipulating the data structure accordingly, or with the second solution by using conditionals (if/else) before invoking the function. However it is impossible to do so with the macros approach unless its DSL is augmented.
44
+
To drive the point home, imagine you want to validate a certain attribute only if a given condition is met. We could easily achieve it with the first solution, by manipulating the data structure accordingly, or with the second solution by using conditionals (if/else) before invoking the function. However, it is impossible to do so with the macros approach unless its DSL is augmented.
45
45
46
46
In other words:
47
47
@@ -119,7 +119,7 @@ iex> defmodule MyTest do
119
119
...> end
120
120
```
121
121
122
-
For now we don't have a mechanism to run tests, but we know that a function named "test hello" was defined behind the scenes. When we invoke it, it should fail:
122
+
For now, we don't have a mechanism to run tests, but we know that a function named "test hello" was defined behind the scenes. When we invoke it, it should fail:
Copy file name to clipboardExpand all lines: getting-started/meta/macros.markdown
+2-2
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ title: Macros
11
11
12
12
Even though Elixir attempts its best to provide a safe environment for macros, the major responsibility of writing clean code with macros falls on developers. Macros are harder to write than ordinary Elixir functions and it's considered to be bad style to use them when they're not necessary. So write macros responsibly.
13
13
14
-
Elixir already provides mechanisms to write your every day code in a simple and readable fashion by using its data structures and functions. Macros should only be used as a last resort. Remember that **explicit is better than implicit**. **Clear code is better than concise code.**
14
+
Elixir already provides mechanisms to write your everyday code in a simple and readable fashion by using its data structures and functions. Macros should only be used as a last resort. Remember that **explicit is better than implicit**. **Clear code is better than concise code.**
15
15
16
16
## Our first macro
17
17
@@ -208,7 +208,7 @@ Take note of the second argument to `Macro.var/2`. This is the context being use
208
208
209
209
When calling `Macro.expand_once/2` earlier in this chapter, we used the special form `__ENV__`.
210
210
211
-
`__ENV__` returns an instance of the `Macro.Env` struct which contains useful information about the compilation environment, including the current module, file and line, all variables defined in the current scope, as well as imports, requires and so on:
211
+
`__ENV__` returns an instance of the `Macro.Env` struct which contains useful information about the compilation environment, including the current module, file, and line, all variables defined in the current scope, as well as imports, requires and so on:
Copy file name to clipboardExpand all lines: getting-started/meta/quote-and-unquote.markdown
+2-2
Original file line number
Diff line number
Diff line change
@@ -154,8 +154,8 @@ iex> Macro.escape(map)
154
154
155
155
Macros receive quoted expressions and must return quoted expressions. However, sometimes during the execution of a macro, you may need to work with values and making a distinction between values and quoted expressions will be required.
156
156
157
-
In other words, it is important to make a distinction between a regular Elixir value (like a list, a map, a process, a reference, etc) and a quoted expression. Some values, such as integers, atoms and strings, have a quoted expression equal to the value itself. Other values, like maps, need to be explicitly converted. Finally, values like functions and references cannot be converted to a quoted expression at all.
157
+
In other words, it is important to make a distinction between a regular Elixir value (like a list, a map, a process, a reference, etc) and a quoted expression. Some values, such as integers, atoms, and strings, have a quoted expression equal to the value itself. Other values, like maps, need to be explicitly converted. Finally, values like functions and references cannot be converted to a quoted expression at all.
158
158
159
159
You can read more about `quote` and `unquote` in the [`Kernel.SpecialForms` module](https://hexdocs.pm/elixir/Kernel.SpecialForms.html). Documentation for `Macro.escape/1` and other functions related to quoted expressions can be found in the [`Macro` module](https://hexdocs.pm/elixir/Macro.html).
160
160
161
-
In this introduction we have laid the groundwork to finally write our first macro, so let's move to the next chapter.
161
+
In this introduction, we have laid the groundwork to finally write our first macro, so let's move to the next chapter.
Copy file name to clipboardExpand all lines: getting-started/mix-otp/agent.markdown
+2-2
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ Elixir is an immutable language where nothing is shared by default. If we want t
20
20
* Processes
21
21
*[ETS (Erlang Term Storage)](http://www.erlang.org/doc/man/ets.html)
22
22
23
-
We covered processes in the Getting Started guide. <abbrtitle="Erlang Term Storage">ETS</abbr> is a new topic that will explore on later chapters. When it comes to processes though, we rarely hand-roll our own, instead we use the abstractions available in Elixir and <abbrtitle="Open Telecom Platform">OTP</abbr>:
23
+
We covered processes in the Getting Started guide. <abbrtitle="Erlang Term Storage">ETS</abbr> is a new topic that will explore in later chapters. When it comes to processes though, we rarely hand-roll our own, instead we use the abstractions available in Elixir and <abbrtitle="Open Telecom Platform">OTP</abbr>:
24
24
25
25
*[Agent](https://hexdocs.pm/elixir/Agent.html) - Simple wrappers around state.
26
26
*[GenServer](https://hexdocs.pm/elixir/GenServer.html) - "Generic servers" (processes) that encapsulate state, provide sync and async calls, support code reloading, and more.
@@ -197,4 +197,4 @@ end
197
197
198
198
When a long action is performed on the server, all other requests to that particular server will wait until the action is done, which may cause some clients to timeout.
199
199
200
-
In the next chapter we will explore GenServers, where the segregation between clients and servers is made more apparent.
200
+
In the next chapter, we will explore GenServers, where the segregation between clients and servers is made more apparent.
0 commit comments