@@ -4,7 +4,7 @@ defmodule IEx do
4
4
@moduledoc % B """
5
5
Welcome to IEx.
6
6
7
- This module is the main entry point Interactive Elixir and
7
+ This module is the main entry point for Interactive Elixir and
8
8
in this documentation we will talk a bit about how IEx works.
9
9
10
10
Notice some of the functionality described here will be available
@@ -20,11 +20,11 @@ defmodule IEx do
20
20
21
21
## The User Switch command
22
22
23
- Besides the break command, one can type Ctrl+G to get the to
24
- the user switch command. When reached, you can type `h` to
23
+ Besides the break command, one can type Ctrl+G to get to the
24
+ user switch command menu . When reached, you can type `h` to
25
25
get more information.
26
26
27
- In this switch , developers are able to create new shell and
27
+ In this menu , developers are able to start new shells and
28
28
alternate in between them. Let's give it a try:
29
29
30
30
User switch command
@@ -36,7 +36,7 @@ defmodule IEx do
36
36
37
37
hello = :world
38
38
39
- Now, let's rollback to the first shell:
39
+ Now, let's roll back to the first shell:
40
40
41
41
User switch command
42
42
--> c 1
@@ -46,23 +46,57 @@ defmodule IEx do
46
46
hello
47
47
** (UndefinedFunctionError) undefined function: IEx.Helpers.hello/0
48
48
49
- The command above fails because we have changed the shells
50
- and they are isolated from each other, you can access the
51
- variables defined in one in the other.
49
+ The command above fails because we have switched the shells.
50
+ Since shells are isolated from each other, you can't access the
51
+ variables defined in one shell from the other one .
52
52
53
- The User Switch also allow developers to connect to remote
54
- shells using r . Keep in mind that you can't connect to a
53
+ The user switch command menu also allows developers to connect to remote
54
+ shells using the "r" command . Keep in mind that you can't connect to a
55
55
remote node if you haven't given a name to the current node
56
56
(i.e. Process.is_alive? must return true).
57
57
58
+ ## The .iex file
59
+
60
+ When starting IEx it will look for a local .iex file (located in the current
61
+ working directory), then a global one (located at ~/.iex) and will load the
62
+ first one it finds (if any). The code in the chosen .iex file will be
63
+ evaluated in the shell's context. So, for instance, any modules that are
64
+ loaded or variables that are bound in the .iex file will be available in the
65
+ shell after it has booted.
66
+
67
+ Sample contents of a local .iex file:
68
+
69
+ # source another .iex file, ~/.iex in this case
70
+ Code.require_file ".iex", "~"
71
+
72
+ # print something before the shell starts
73
+ IO.puts "hello world"
74
+
75
+ # bind a variable that'll be accessible in the shell
76
+ value = 13
77
+
78
+ Running the shell in the directory where the above .iex file is located
79
+ results in
80
+
81
+ $ iex
82
+ Erlang R15B03 (erts-5.9.3.1) [...]
83
+
84
+ hello world
85
+ Interactive Elixir (0.8.3.dev) - press Ctrl+C to exit (type h() ENTER for help)
86
+ iex(1)> value
87
+ 13
88
+
89
+ If you want to erase all variables bound in the .iex file, call the f()
90
+ helper at the end.
91
+
58
92
## Expressions in IEx
59
93
60
94
As an interactive shell, IEx evalutes expressions. This has some
61
- interesting consequences worthy discussing.
95
+ interesting consequences that are worth discussing.
62
96
63
97
The first one is that the code is truly evaluated and not compiled.
64
- This means that, any benchmarking done in the shell is going to have
65
- skewed results. So never run any profiling nor benchmark in the shell.
98
+ This means that any benchmarking done in the shell is going to have
99
+ skewed results. So never run any profiling nor benchmarks in the shell.
66
100
67
101
Second of all, IEx alows you to break an expression into many lines,
68
102
since this is common in Elixir. For example:
@@ -206,28 +240,6 @@ defmodule IEx do
206
240
end
207
241
208
242
# Locates and loads an .iex file from one of predefined locations
209
- #
210
- # Sample contents of a local .iex file:
211
- #
212
- # # source another .iex file, ~/.iex in this case
213
- # Code.require_file " . iex ", "~"
214
- #
215
- # # print something before the shell starts
216
- # IO.puts "hello world"
217
- #
218
- # # bind a variable that'll be accessible in the shell
219
- # value = 13
220
- #
221
- # Running the shell then results in
222
- #
223
- # $ iex
224
- # Erlang R15B03 (erts-5.9.3.1) ...
225
- #
226
- # hello world
227
- # Interactive Elixir (0.8.3.dev) - press Ctrl+C to exit (type h() ENTER for help)
228
- # iex(1)> value
229
- # 13
230
- #
231
243
defp load_dot_iex(config) do
232
244
path = Enum.find [" . iex ", " ~/. iex "], File.regular?(&1)
233
245
if nil?(path) do
0 commit comments