@@ -4,7 +4,7 @@ defmodule IEx do
44 @moduledoc % B """
55 Welcome to IEx.
66
7- This module is the main entry point Interactive Elixir and
7+ This module is the main entry point for Interactive Elixir and
88 in this documentation we will talk a bit about how IEx works.
99
1010 Notice some of the functionality described here will be available
@@ -20,11 +20,11 @@ defmodule IEx do
2020
2121 ## The User Switch command
2222
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
2525 get more information.
2626
27- In this switch , developers are able to create new shell and
27+ In this menu , developers are able to start new shells and
2828 alternate in between them. Let's give it a try:
2929
3030 User switch command
@@ -36,7 +36,7 @@ defmodule IEx do
3636
3737 hello = :world
3838
39- Now, let's rollback to the first shell:
39+ Now, let's roll back to the first shell:
4040
4141 User switch command
4242 --> c 1
@@ -46,23 +46,57 @@ defmodule IEx do
4646 hello
4747 ** (UndefinedFunctionError) undefined function: IEx.Helpers.hello/0
4848
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 .
5252
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
5555 remote node if you haven't given a name to the current node
5656 (i.e. Process.is_alive? must return true).
5757
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+
5892 ## Expressions in IEx
5993
6094 As an interactive shell, IEx evalutes expressions. This has some
61- interesting consequences worthy discussing.
95+ interesting consequences that are worth discussing.
6296
6397 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.
66100
67101 Second of all, IEx alows you to break an expression into many lines,
68102 since this is common in Elixir. For example:
@@ -206,28 +240,6 @@ defmodule IEx do
206240 end
207241
208242 # 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- #
231243 defp load_dot_iex(config) do
232244 path = Enum.find [" . iex ", " ~/. iex "], File.regular?(&1)
233245 if nil?(path) do
0 commit comments