File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
77warrant a full blog post. These are mostly things I learn by pairing with
88smart people at [ Hashrocket] ( http://hashrocket.com/ ) .
99
10- _ 512 TILs and counting..._
10+ _ 513 TILs and counting..._
1111
1212---
1313
@@ -104,6 +104,7 @@ _512 TILs and counting..._
104104- [ Pattern Matching In Anonymous Functions] ( elixir/pattern-matching-in-anonymous-functions.md )
105105- [ Quitting IEx] ( elixir/quitting-iex.md )
106106- [ Range Into List Using Comprehensions] ( elixir/range-into-list-using-comprehensions.md )
107+ - [ Referencing Values In IEx's History] ( elixir/referencing-values-in-iexs-history.md )
107108- [ Replace Duplicates In A Keyword List] ( elixir/replace-duplicates-in-a-keyword-list.md )
108109- [ Requiring Keys For Structs] ( elixir/requiring-keys-for-structs.md )
109110- [ Reversing A List] ( elixir/reversing-a-list.md )
Original file line number Diff line number Diff line change 1+ # Referencing Values In IEx's History
2+
3+ Each time we execute a statement in an ` iex ` session, the counter is
4+ incremented. These numbers are references to the history of the session. We
5+ can use these references to _ refer_ to previously executed values using
6+ ` v/1 ` . This is particularly handy for multi-line statements or when we
7+ forget to bind to the result of some function.
8+
9+ Consider the following ` iex ` session:
10+
11+ ``` elixir
12+ iex (1 )> :one
13+ :one
14+ iex (2 )> 1 + 1
15+ 2
16+ iex (3 )> " three" |> String .to_atom ()
17+ :three
18+ ```
19+
20+ If we execute ` v() ` on its own, it is the same as ` v(-1) ` in that it will
21+ give us the latest value in the history.
22+
23+ ``` elixir
24+ iex (4 )> v ()
25+ :three
26+ ```
27+
28+ Providing any positive number will refer to the references we see next to
29+ each statement.
30+
31+ ``` elixir
32+ iex (5 )> v (1 )
33+ :one
34+ ```
35+
36+ Negative numbers, as we saw with ` v(-1) ` , will count backwards in the
37+ history from where we are.
38+
39+ ``` elixir
40+ iex (6 )> v (- 4 )
41+ 2
42+ ```
43+
44+ See ` h v ` for more details.
You can’t perform that action at this time.
0 commit comments