Skip to content

Commit fd659a5

Browse files
committed
Merge pull request elixir-lang#448 from eksperimental/getting_started_headings
Getting started headings
2 parents 14fc016 + 9de7205 commit fd659a5

36 files changed

+220
-257
lines changed

_includes/bottom.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
$(document).ready(function() {
2727
$('.toc').toc({
2828
title: '',
29-
listType: 'ul',
29+
listType: 'ol',
3030
minimumHeaders: 2,
3131
headers: 'h2, h3, h4, h5, h6',
3232
showSpeed: 0,

_posts/2013-12-11-elixir-s-new-continuable-enumerators.markdown

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ the basis of a zip function. Without interleaving you cannot implement
8989

9090
The underlying problem, in both cases, is that the producer is fully in control.
9191
The producer simply pushes out as many elements to the consumer as it wants and
92-
then says "I'm done". There's no way aside from `throw`/`raise` for a consumer
92+
then says "I'm done". There's no way aside from `throw/raise` for a consumer
9393
to tell a producer "stop producing". There is definitely no way to tell a
9494
producer "stop for now but be prepared to continue where you left off later".
9595

getting-started/alias-require-and-import.markdown

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
22
layout: getting-started
3-
title: 13 alias, require and import
4-
guide: 13
5-
redirect_from: "/getting_started/13.html"
3+
title: alias, require and import
4+
redirect_from: /getting_started/13.html
65
---
76

87
# {{ page.title }}
@@ -11,7 +10,7 @@ redirect_from: "/getting_started/13.html"
1110

1211
In order to facilitate software reuse, Elixir provides three directives. As we are going to see below, they are called directives because they have **lexical scope**.
1312

14-
## 13.1 alias
13+
## `alias`
1514

1615
`alias` allows you to set up aliases for any given module name. Imagine our `Math` module uses a special list implementation for doing math specific operations:
1716

@@ -60,7 +59,7 @@ end
6059

6160
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.
6261

63-
## 13.2 require
62+
## `require`
6463

6564
Elixir provides macros as a mechanism for meta-programming (writing code that generates code).
6665

@@ -79,7 +78,7 @@ In Elixir, `Integer.is_odd/1` is defined as a macro so that it can be used as a
7978

8079
In general a module does not need to be required before usage, except if we want to use the macros available in that module. An attempt to call a macro that was not loaded will raise an error. Note that like the `alias` directive, `require` is also lexically scoped. We will talk more about macros in a later chapter.
8180

82-
## 13.3 import
81+
## `import`
8382

8483
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:
8584

@@ -119,7 +118,7 @@ In the example above, the imported `List.duplicate/2` is only visible within tha
119118

120119
Note that `import`ing a module automatically `require`s it.
121120

122-
## 13.4 Aliases
121+
## Aliases
123122

124123
At this point you may be wondering: what exactly an Elixir alias is and how is it represented?
125124

@@ -154,7 +153,7 @@ iex> mod.flatten([1, [2], 3])
154153

155154
We are simply calling the function `flatten` on the atom `:lists`.
156155

157-
## 13.5 Nesting
156+
## Nesting
158157

159158
Now that we have talked about aliases, we can talk about nesting and how it works in Elixir. Consider the following example:
160159

getting-started/basic-operators.markdown

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
22
layout: getting-started
3-
title: 3 Basic operators
4-
guide: 3
5-
redirect_from: "/getting_started/3.html"
3+
title: Basic operators
4+
redirect_from: /getting_started/3.html
65
---
76

87
# {{ page.title }}

getting-started/basic-types.markdown

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
22
layout: getting-started
3-
title: 2 Basic types
4-
guide: 2
5-
redirect_from: "/getting_started/2.html"
3+
title: Basic types
4+
redirect_from: /getting_started/2.html
65
---
76

87
# {{ page.title }}
@@ -22,7 +21,7 @@ iex> [1, 2, 3] # list
2221
iex> {1, 2, 3} # tuple
2322
```
2423

25-
## 2.1 Basic arithmetic
24+
## Basic arithmetic
2625

2726
Open up `iex` and type the following expressions:
2827

@@ -79,7 +78,7 @@ iex> trunc 3.58
7978
3
8079
```
8180

82-
## 2.2 Booleans
81+
## Booleans
8382

8483
Elixir supports `true` and `false` as booleans:
8584

@@ -105,7 +104,7 @@ You can also use `is_integer/1`, `is_float/1` or `is_number/1` to check, respect
105104

106105
> Note: At any moment you can type `h` in the shell to print information on how to use the shell. The `h` helper can also be used to access documentation for any function. For example, typing `h is_integer/1` is going to print the documentation for the `is_integer/1` function. It also works with operators and other constructs (try `h ==/2`).
107106
108-
## 2.3 Atoms
107+
## Atoms
109108

110109
Atoms are constants where their name is their own value. Some other languages call these symbols:
111110

@@ -127,7 +126,7 @@ iex> is_boolean(:false)
127126
true
128127
```
129128

130-
## 2.4 Strings
129+
## Strings
131130

132131
Strings in Elixir are inserted between double quotes, and they are encoded in UTF-8:
133132

@@ -194,7 +193,7 @@ iex> String.upcase("hellö")
194193
"HELLÖ"
195194
```
196195

197-
## 2.5 Anonymous functions
196+
## Anonymous functions
198197

199198
Functions are delimited by the keywords `fn` and `end`:
200199

@@ -235,7 +234,7 @@ iex> x
235234
42
236235
```
237236

238-
## 2.6 (Linked) Lists
237+
## (Linked) Lists
239238

240239
Elixir uses square brackets to specify a list of values. Values can be of any type:
241240

@@ -292,7 +291,7 @@ false
292291

293292
Single-quotes are char lists, double-quotes are strings. We will talk more about them in the "Binaries, strings and char lists" chapter.
294293

295-
## 2.7 Tuples
294+
## Tuples
296295

297296
Elixir uses curly brackets to define tuples. Like lists, tuples can hold any value:
298297

@@ -329,7 +328,7 @@ Notice that `put_elem/3` returned a new tuple. The original tuple stored in the
329328

330329
By being immutable, Elixir also helps eliminate common cases where concurrent code has race conditions because two different entities are trying to change a data structure at the same time.
331330

332-
## 2.8 Lists or tuples?
331+
## Lists or tuples?
333332

334333
What is the difference between lists and tuples?
335334

getting-started/binaries-strings-and-char-lists.markdown

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
22
layout: getting-started
3-
title: 6 Binaries, strings and char lists
4-
guide: 6
5-
redirect_from: "/getting_started/6.html"
3+
title: Binaries, strings and char lists
4+
redirect_from: /getting_started/6.html
65
---
76

87
# {{ page.title }}
@@ -20,7 +19,7 @@ true
2019

2120
In this chapter, we will understand what binaries are, how they associate with strings, and what a single-quoted value, `'like this'`, means in Elixir.
2221

23-
## 6.1 UTF-8 and Unicode
22+
## UTF-8 and Unicode
2423

2524
A string is a UTF-8 encoded binary. In order to understand exactly what we mean by that, we need to understand the difference between bytes and code points.
2625

@@ -59,7 +58,7 @@ You will see that Elixir has excellent support for working with strings. It also
5958

6059
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!
6160

62-
## 6.2 Binaries (and bitstrings)
61+
## Binaries (and bitstrings)
6362

6463
In Elixir, you can define a binary using `<<>>`:
6564

@@ -154,7 +153,7 @@ iex> rest
154153

155154
This finishes our tour of bitstrings, binaries and strings. A string is a UTF-8 encoded binary, and a binary is a bitstring where the number of bits is divisible by 8. Although this shows the flexibility Elixir provides to work with bits and bytes, 99% of the time you will be working with binaries and using the `is_binary/1` and `byte_size/1` functions.
156155

157-
## 6.3 Char lists
156+
## Char lists
158157

159158
A char list is nothing more than a list of characters:
160159

getting-started/case-cond-and-if.markdown

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
22
layout: getting-started
3-
title: 5 case, cond and if
4-
guide: 5
5-
redirect_from: "/getting_started/5.html"
3+
title: case, cond and if
4+
redirect_from: /getting_started/5.html
65
---
76

87
# {{ page.title }}
@@ -11,7 +10,7 @@ redirect_from: "/getting_started/5.html"
1110

1211
In this chapter, we will learn about the `case`, `cond` and `if` control-flow structures.
1312

14-
## 5.1 case
13+
## `case`
1514

1615
`case` allows us to compare a value against many patterns until we find a matching one:
1716

@@ -50,7 +49,7 @@ iex> case {1, 2, 3} do
5049

5150
The first clause above will only match when `x` is positive.
5251

53-
## 5.2 Expressions in guard clauses.
52+
## Expressions in guard clauses
5453

5554
The Erlang Virtual Machine (VM) only allows a limited set of expressions in guards:
5655

@@ -134,7 +133,7 @@ iex> f.(-1, 3)
134133

135134
The number of arguments in each anonymous function clause needs to be the same, otherwise an error is raised.
136135

137-
## 5.3 cond
136+
## `cond`
138137

139138
`case` is useful when you need to match against different values. However, in many circumstances, we want to check different conditions and find the first one that evaluates to true. In such cases, one may use `cond`:
140139

@@ -175,7 +174,7 @@ iex> cond do
175174
"1 is considered as true"
176175
```
177176

178-
## 5.4 if and unless
177+
## `if` and `unless`
179178

180179
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:
181180

@@ -205,16 +204,16 @@ iex> if nil do
205204

206205
> Note: An interesting note regarding `if/2` and `unless/2` is that they are implemented as macros in the language; they aren't special language constructs as they would be in many languages. You can check the documentation and the source of `if/2` in [the `Kernel` module docs](/docs/stable/elixir/Kernel.html). The `Kernel` module is also where operators like `+/2` and functions like `is_function/2` are defined, all automatically imported and available in your code by default.
207206
208-
## 5.5 `do`/`end` blocks
207+
## `do/end` blocks
209208

210-
At this point, we have learned four control structures: `case`, `cond`, `if` and `unless`, and they were all wrapped in `do`/`end` blocks. It happens we could also write `if` as follows:
209+
At this point, we have learned four control structures: `case`, `cond`, `if` and `unless`, and they were all wrapped in `do/end` blocks. It happens we could also write `if` as follows:
211210

212211
```iex
213212
iex> if true, do: 1 + 2
214213
3
215214
```
216215

217-
In Elixir, `do`/`end` blocks are a convenience for passing a group of expressions to `do:`. These are equivalent:
216+
In Elixir, `do/end` blocks are a convenience for passing a group of expressions to `do:`. These are equivalent:
218217

219218
```iex
220219
iex> if true do
@@ -236,7 +235,7 @@ iex> if false, do: :this, else: :that
236235
:that
237236
```
238237

239-
One thing to keep in mind when using `do`/`end` blocks is they are always bound to the outermost function call. For example, the following expression:
238+
One thing to keep in mind when using `do/end` blocks is they are always bound to the outermost function call. For example, the following expression:
240239

241240
```iex
242241
iex> is_number if true do

getting-started/comprehensions.markdown

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
22
layout: getting-started
3-
title: 17 Comprehensions
4-
guide: 17
5-
redirect_from: "/getting_started/17.html"
3+
title: Comprehensions
4+
redirect_from: /getting_started/17.html
65
---
76

87
# {{ page.title }}
@@ -20,7 +19,7 @@ iex> for n <- [1, 2, 3, 4], do: n * n
2019

2120
A comprehension is made of three parts: generators, filters and collectables.
2221

23-
## 17.1 Generators and filters
22+
## Generators and filters
2423

2524
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:
2625

@@ -60,7 +59,7 @@ end
6059

6160
Keep in mind that variable assignments inside the comprehension, be it in generators, filters or inside the block, are not reflected outside of the comprehension.
6261

63-
## 17.2 Bitstring generators
62+
## Bitstring generators
6463

6564
Bitstring generators are also supported and are very useful when you need to comprehend over bitstring streams. The example below receives a list of pixels from a binary with their respective red, green and blue values and converts them into tuples of three elements each:
6665

@@ -72,7 +71,7 @@ iex> for <<r::8, g::8, b::8 <- pixels>>, do: {r, g, b}
7271

7372
A bitstring generator can be mixed with the "regular" enumerable generators and provides filters as well.
7473

75-
## 17.3 Results other than lists
74+
## Results other than lists
7675

7776
In the examples above, all the comprehensions returned lists as their result. However, the result of a comprehension can be inserted into different data structures by passing the `:into` option to the comprehension.
7877

getting-started/enumerables-and-streams.markdown

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
---
22
layout: getting-started
3-
title: 10 Enumerables and Streams
4-
guide: 10
5-
redirect_from: "/getting_started/10.html"
3+
title: Enumerables and Streams
4+
redirect_from: /getting_started/10.html
65
---
76

87
# {{ page.title }}
98

109
{% include toc.html %}
1110

12-
## 10.1 Enumerables
11+
## Enumerables
1312

1413
Elixir provides the concept of enumerables and [the `Enum` module](/docs/stable/elixir/Enum.html) to work with them. We have already learned two enumerables: lists and maps.
1514

@@ -35,7 +34,7 @@ Since the Enum module was designed to work across different data types, its API
3534

3635
We say the functions in the `Enum` module are polymorphic because they can work with diverse data types. In particular, the functions in the `Enum` module can work with any data type that implements [the `Enumerable` protocol](/docs/stable/elixir/Enumerable.html). We are going to discuss Protocols in a later chapter, for now we are going to move on to a specific kind of enumerable called streams.
3736

38-
## 10.2 Eager vs Lazy
37+
## Eager vs Lazy
3938

4039
All the functions in the `Enum` module are eager. Many functions expect an enumerable and return a list back:
4140

@@ -55,7 +54,7 @@ iex> 1..100_000 |> Enum.map(&(&1 * 3)) |> Enum.filter(odd?) |> Enum.sum
5554

5655
The example above has a pipeline of operations. We start with a range and then multiply each element in the range by 3. This first operation will now create and return a list with `100_000` items. Then we keep all odd elements from the list, generating a new list, now with `50_000` items, and then we sum all entries.
5756

58-
### 10.2.1 The pipe operator
57+
### The pipe operator
5958

6059
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 input 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:
6160

@@ -66,7 +65,7 @@ iex> Enum.sum(Enum.filter(Enum.map(1..100_000, &(&1 * 3)), odd?))
6665

6766
Find more about the pipe operator [by reading its documentation](http://elixir-lang.org/docs/stable/elixir/Kernel.html#|>/2).
6867

69-
## 10.3 Streams
68+
## Streams
7069

7170
As an alternative to `Enum`, Elixir provides [the `Stream` module](/docs/stable/elixir/Stream.html) which supports lazy operations:
7271

getting-started/introduction.markdown

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
---
22
layout: getting-started
3-
title: 1 Introduction
4-
guide: 1
5-
redirect_from: "/getting_started/1.html"
3+
title: Introduction
4+
redirect_from: /getting_started/1.html
65
---
76

87
# {{ page.title }}
@@ -22,11 +21,11 @@ Let's get started!
2221

2322
> If you find any errors in the tutorial or on the website, [please report a bug or send a pull request to our issue tracker](https://github.com/elixir-lang/elixir-lang.github.com). If you suspect it is a language bug, [please let us know in the language issue tracker](https://github.com/elixir-lang/elixir/issues).
2423
25-
## 1.1 Installation
24+
## Installation
2625

2726
If you still haven't installed Elixir, run to our [installation page](/install.html). Once you are done, you can run `elixir -v` to get the current Elixir version.
2827

29-
## 1.2 Interactive mode
28+
## Interactive mode
3029

3130
When you install Elixir, you will have three new executables: `iex`, `elixir` and `elixirc`. If you compiled Elixir from source or are using a packaged version, you can find these inside the `bin` directory.
3231

@@ -43,7 +42,7 @@ iex> "hello" <> " world"
4342

4443
It seems we are ready to go! We will use the interactive shell quite a lot in the next chapters to get a bit more familiar with the language constructs and basic types, starting in the next chapter.
4544

46-
## 1.3 Running scripts
45+
## Running scripts
4746

4847
After getting familiar with the basics of the language you may want to try writing simple programs. This can be accomplished by putting Elixir code into a file and executing it with `elixir`:
4948

0 commit comments

Comments
 (0)