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
+3-14Lines changed: 3 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,7 +72,7 @@ defmodule Math do
72
72
end
73
73
```
74
74
75
-
In the example above, since we are invoking `alias` inside the function `plus/2`, the alias will just be valid inside the function `plus/2`. `minus/2` won't be affected at all.
75
+
In the example above, since we are invoking `alias` inside the function `plus/2`, the alias will be valid only inside the function `plus/2`. `minus/2` won't be affected at all.
76
76
77
77
## require
78
78
@@ -95,7 +95,7 @@ In general a module does not need to be required before usage, except if we want
95
95
96
96
## import
97
97
98
-
We use `import` whenever we want to easily access functions or macros from other modules without using the fully-qualified name. For instance, if we want to use the `duplicate/2` function from the `List` module several times, we can simply import it:
98
+
We use `import` whenever we want to easily access functions or macros from other modules without using the fully-qualified name. For instance, if we want to use the `duplicate/2` function from the `List` module several times, we can import it:
By using the `alias/2` directive, we are simply changing the atom the alias expands to.
186
+
By using the `alias/2` directive, we are changing the atom the alias expands to.
187
187
188
188
Aliases expand to atoms because in the Erlang <abbrtitle="Virtual Machine">VM</abbr> (and consequently Elixir) modules are always represented by atoms. For example, that's the mechanism we use to call Erlang modules:
Copy file name to clipboardExpand all lines: getting-started/basic-types.markdown
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -209,7 +209,7 @@ iex> add.(1, 2)
209
209
3
210
210
```
211
211
212
-
Functions are "first class citizens" in Elixir meaning they can be passed as arguments to other functions just as integers and strings can. In the example, we have passed the function in the variable `add` to the `is_function/1` function which correctly returned `true`. We can also check the arity of the function by calling `is_function/2`.
212
+
Functions are "first class citizens" in Elixir meaning they can be passed as arguments to other functions as integers and strings can. In the example, we have passed the function in the variable `add` to the `is_function/1` function which correctly returned `true`. We can also check the arity of the function by calling `is_function/2`.
213
213
214
214
Note a dot (`.`) between the variable and parenthesis is required to invoke an anonymous function.
Copy file name to clipboardExpand all lines: getting-started/binaries-strings-and-char-lists.markdown
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,7 @@ iex> String.codepoints("hełło")
57
57
58
58
You will see that Elixir has excellent support for working with strings. It also supports many of the Unicode operations. In fact, Elixir passes all the tests showcased in the article ["The string type is broken"](http://mortoray.com/2013/11/27/the-string-type-is-broken/).
59
59
60
-
However, strings are just part of the story. If a string is a binary, and we have used the `is_binary/1` function, Elixir must have an underlying type empowering strings. And it does. Let's talk about binaries!
60
+
However, strings are just part of the story. If a string is a binary, and we have used the `is_binary/1` function, Elixir must have an underlying type empowering strings. And it does! Let's talk about binaries.
61
61
62
62
## Binaries (and bitstrings)
63
63
@@ -70,7 +70,7 @@ iex> byte_size(<<0, 1, 2, 3>>)
70
70
4
71
71
```
72
72
73
-
A binary is just a sequence of bytes. Of course, those bytes can be organized in any way, even in a sequence that does not make them a valid string:
73
+
A binary is a sequence of bytes. Those bytes can be organized in any way, even in a sequence that does not make them a valid string:
Copy file name to clipboardExpand all lines: getting-started/case-cond-and-if.markdown
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -104,7 +104,7 @@ module defines guards as functions and operators: `bnot`, `~~~`, `band`,
104
104
Note that while boolean operators such as `and`, `or`, `not` are allowed in guards,
105
105
the more general and short-circuiting operators `&&`, `||` and `!` are not.
106
106
107
-
Keep in mind errors in guards do not leak but simply make the guard fail:
107
+
Keep in mind errors in guards do not leak but instead make the guard fail:
108
108
109
109
```iex
110
110
iex> hd(1)
@@ -194,7 +194,7 @@ iex> cond do
194
194
195
195
## `if` and `unless`
196
196
197
-
Besides `case` and `cond`, Elixir also provides the macros `if/2` and `unless/2` which are useful when you need to check for just one condition:
197
+
Besides `case` and `cond`, Elixir also provides the macros `if/2` and `unless/2` which are useful when you need to check for only one condition:
198
198
199
199
```iex
200
200
iex> if true do
@@ -207,7 +207,7 @@ iex> unless true do
207
207
nil
208
208
```
209
209
210
-
If the condition given to `if/2` returns `false` or `nil`, the body given between `do/end` is not executed and it simply returns `nil`. The opposite happens with `unless/2`.
210
+
If the condition given to `if/2` returns `false` or `nil`, the body given between `do/end` is not executed and instead it returns `nil`. The opposite happens with `unless/2`.
Copy file name to clipboardExpand all lines: getting-started/enumerables-and-streams.markdown
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ The example above has a pipeline of operations. We start with a range and then m
55
55
56
56
## The pipe operator
57
57
58
-
The `|>` symbol used in the snippet above is the **pipe operator**: it simply takes the output from the expression on its left side and passes it as the first argument to the function call on its right side. It's similar to the Unix `|` operator. Its purpose is to highlight the flow of data being transformed by a series of functions. To see how it can make the code cleaner, have a look at the example above rewritten without using the `|>` operator:
58
+
The `|>` symbol used in the snippet above is the **pipe operator**: it takes the output from the expression on its left side and passes it as the first argument to the function call on its right side. It's similar to the Unix `|` operator. Its purpose is to highlight the data being transformed by a series of functions. To see how it can make the code cleaner, have a look at the example above rewritten without using the `|>` operator:
Copy file name to clipboardExpand all lines: getting-started/io-and-the-file-system.markdown
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,7 +94,7 @@ iex> Path.expand("~/hello")
94
94
"/Users/jose/hello"
95
95
```
96
96
97
-
Using functions from the `Path` module as opposed to just manipulating binaries 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.
97
+
Using functions from the `Path` module as opposed to directly manipulating string 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.
98
98
99
99
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.
100
100
@@ -147,7 +147,7 @@ The group leader can be configured per process and is used in different situatio
147
147
148
148
## `iodata` and `chardata`
149
149
150
-
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 simply bytes while char lists are lists with code points.
150
+
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.
151
151
152
152
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:
153
153
@@ -160,7 +160,7 @@ hello world
160
160
:ok
161
161
```
162
162
163
-
However, this 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.
163
+
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.
164
164
165
165
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-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,17 +69,17 @@ end
69
69
MyTest.run
70
70
```
71
71
72
-
In the example above, by using `TestCase`, we can write tests using the `test` macro, which defines a function named `run` to automatically run all tests for us. Our prototype will simply rely on the match operator (`=`) as a mechanism to do assertions.
72
+
In the example above, by using `TestCase`, we can write tests using the `test` macro, which defines a function named `run` to automatically run all tests for us. Our prototype will rely on the match operator (`=`) as a mechanism to do assertions.
73
73
74
74
## The `test` macro
75
75
76
-
Let's start by creating a module that simply defines and imports the `test` macro when used:
76
+
Let's start by creating a module that defines and imports the `test` macro when used:
77
77
78
78
```elixir
79
79
defmoduleTestCasedo
80
80
# Callback invoked by `use`.
81
81
#
82
-
# For now it simply returns a quoted expression that
Copy file name to clipboardExpand all lines: getting-started/mix-otp/dependencies-and-umbrella-apps.markdown
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,7 +79,7 @@ Internal dependencies are the ones that are specific to your project. They usual
79
79
80
80
If you have an internal dependency, Mix supports two methods to work with them: git repositories or umbrella projects.
81
81
82
-
For example, if you push the `kv` project to a git repository, you just need to list it in your deps code in order to use it:
82
+
For example, if you push the `kv` project to a git repository, you'll need to list it in your deps code in order to use it:
83
83
84
84
```elixir
85
85
defdepsdo
@@ -139,7 +139,7 @@ defmodule KvUmbrella.Mixfile do
139
139
end
140
140
```
141
141
142
-
What makes this project different from the previous one is simply the `apps_path: "apps"` entry in the project definition. This means this project will act as an umbrella. Such projects do not have source files nor tests, although they can have their own dependencies (not shared with children). We'll create new applications inside the apps directory.
142
+
What makes this project different from the previous one is the `apps_path: "apps"` entry in the project definition. This means this project will act as an umbrella. Such projects do not have source files nor tests, although they can have their own dependencies. Each child application must be defined inside the `apps` directory.
143
143
144
144
Let's move inside the apps directory and start building `kv_server`. This time, we are going to pass the `--sup` flag, which will tell Mix to generate a supervision tree automatically for us, instead of building one manually as we did in previous chapters:
145
145
@@ -260,7 +260,7 @@ Finally, copy the `kv` application we have built so far to the `apps` directory
260
260
+ kv
261
261
+ kv_server
262
262
263
-
We now just need to modify `apps/kv/mix.exs` to contain the umbrella entries we have seen in `apps/kv_server/mix.exs`. Open up `apps/kv/mix.exs` and add to the `project` function:
263
+
We now need to modify `apps/kv/mix.exs` to contain the umbrella entries we have seen in `apps/kv_server/mix.exs`. Open up `apps/kv/mix.exs` and add to the `project` function:
0 commit comments