@@ -76,19 +76,6 @@ defmodule IEx.Helpers do
7676 end
7777 end
7878
79- @ doc """
80- Prints the history of expressions evaluated during the session along with
81- their results.
82- """
83- def v do
84- history = :queue . to_list ( Process . get ( :iex_history ) )
85- Enum . each ( history , print_history ( & 1 ) )
86- end
87-
88- defp print_history ( config ) do
89- IO . puts IEx . color ( :info , "#{ config . counter } : #{ config . cache } #=> #{ inspect config . result } \n " )
90- end
91-
9279 @ doc """
9380 Prints the documentation for `IEx.Helpers`.
9481 """
@@ -218,49 +205,26 @@ defmodule IEx.Helpers do
218205 end
219206
220207 @ doc """
221- Retrieves nth expression's value from the history.
222-
223- Use negative values to lookup expression values relative to the current one.
224- For instance, v(-1) returns the result of the last evaluated expression.
208+ Prints the history of expressions evaluated during the session along with
209+ their results.
225210 """
226- def v ( n ) when n < 0 do
227- history = Process . get ( :iex_history )
228- queue_nth_r ( history , abs ( n ) - 1 , :queue . len ( history ) ) . result
229- end
230-
231- def v ( n ) when n > 0 do
232- history = Process . get ( :iex_history )
233- queue_nth ( history , n - 1 , :queue . len ( history ) ) . result
234- end
235-
236- defp queue_nth ( _ , _ , 0 ) do
237- raise_bounds
238- end
239-
240- defp queue_nth ( queue , 0 , _ ) do
241- { :value , value } = :queue . peek ( queue )
242- value
243- end
244-
245- defp queue_nth ( queue , n , len ) when n > 0 do
246- queue_nth ( :queue . drop ( queue ) , n - 1 , len - 1 )
247- end
248-
249- defp queue_nth_r ( _ , _ , 0 ) do
250- raise_bounds
211+ def v do
212+ IEx.History . each ( print_history_entry ( & 1 ) )
251213 end
252214
253- defp queue_nth_r ( queue , 0 , _ ) do
254- { :value , value } = :queue . peek_r ( queue )
255- value
215+ defp print_history_entry ( config ) do
216+ IO . write IEx . color ( :info , " #{ config . counter } : #{ config . cache } #=> " )
217+ IO . puts IEx . color ( :eval_result , " #{ inspect config . result } \n " )
256218 end
257219
258- defp queue_nth_r ( queue , n , len ) when n > 0 do
259- queue_nth ( :queue . drop_r ( queue ) , n - 1 , len - 1 )
260- end
220+ @ doc """
221+ Retrieves nth expression's value from the history.
261222
262- defp raise_bounds do
263- raise "Out of bounds"
223+ Use negative values to lookup expression values relative to the current one.
224+ For instance, v(-1) returns the result of the last evaluated expression.
225+ """
226+ def v ( n ) do
227+ IEx.History . nth ( n ) . result
264228 end
265229
266230 @ doc """
0 commit comments