@@ -13,11 +13,7 @@ defprotocol Inspect do
1313 followed by the inspecting options, represented by the record
1414 `Inspect.Opts`.
1515
16- Inspection is done using the functions available in
17- `Inspect.Algebra` and by calling `Kernel.inspect/2` recursively
18- passing the `Inspect.Opts` as an argument. When `Kernel.inspect/2`
19- receives an `Inspect.Opts` record as the second argument, it returns
20- the underlying algebra document instead of the formatted string.
16+ Inspection is done using the functions available in `Inspect.Algebra`.
2117
2218 ## Examples
2319
@@ -29,15 +25,15 @@ defprotocol Inspect do
2925 import Inspect.Algebra
3026
3127 def inspect(dict, opts) do
32- concat ["#HashSet<", Kernel.inspect (HashSet.to_list(dict), opts), ">"]
28+ concat ["#HashSet<", to_doc (HashSet.to_list(dict), opts), ">"]
3329 end
3430 end
3531
3632 The `concat` function comes from `Inspect.Algebra` and it
3733 concatenates algebra documents together. In the example above,
3834 it is concatenating the string `"HashSet<"` (all strings are
3935 valid algebra documents that keep their formatting when pretty
40- printed), the document returned by `Kernel.inspect /2` and the
36+ printed), the document returned by `Inspect.Algebra.to_doc /2` and the
4137 other string `">"`.
4238
4339 Since regular strings are valid entities in an algebra document,
@@ -281,14 +277,14 @@ defimpl Inspect, for: List do
281277 keyword? ( thing ) && not opts . raw ->
282278 surround_many ( "[" , thing , "]" , opts . limit , & keyword ( & 1 , opts ) )
283279 true ->
284- surround_many ( "[" , thing , "]" , opts . limit , & Kernel . inspect ( & 1 , opts ) )
280+ surround_many ( "[" , thing , "]" , opts . limit , & to_doc ( & 1 , opts ) )
285281 end
286282 end
287283
288284 defp keyword ( { key , value } , opts ) do
289285 concat (
290286 key_to_binary ( key ) <> ": " ,
291- Kernel . inspect ( value , opts )
287+ to_doc ( value , opts )
292288 )
293289 end
294290
@@ -329,7 +325,7 @@ defimpl Inspect, for: Tuple do
329325 def inspect ( tuple , opts ) do
330326 unless opts . raw do
331327 record_inspect ( tuple , opts )
332- end || surround_many ( "{" , tuple_to_list ( tuple ) , "}" , opts . limit , & Kernel . inspect ( & 1 , opts ) )
328+ end || surround_many ( "{" , tuple_to_list ( tuple ) , "}" , opts . limit , & to_doc ( & 1 , opts ) )
333329 end
334330
335331 ## Helpers
@@ -339,7 +335,7 @@ defimpl Inspect, for: Tuple do
339335
340336 if is_atom ( name ) && ( fields = record_fields ( name ) ) && ( length ( fields ) == size ( record ) - 1 ) do
341337 surround_record ( name , fields , tail , opts )
342- end || surround_many ( "{" , [ name | tail ] , "}" , opts . limit , & Kernel . inspect ( & 1 , opts ) )
338+ end || surround_many ( "{" , [ name | tail ] , "}" , opts . limit , & to_doc ( & 1 , opts ) )
343339 end
344340
345341 defp record_fields ( name ) do
@@ -373,7 +369,7 @@ defimpl Inspect, for: Tuple do
373369 end
374370
375371 defp keyword ( { k , v } , opts ) do
376- concat ( k <> ": " , Kernel . inspect ( v , opts ) )
372+ concat ( k <> ": " , to_doc ( v , opts ) )
377373 end
378374end
379375
@@ -422,11 +418,11 @@ defimpl Inspect, for: Regex do
422418
423419 """
424420 def inspect ( regex , opts ) when size ( regex ) == 5 do
425- concat [ "%r" , Kernel . inspect ( Regex . source ( regex ) , opts ) , Regex . opts ( regex ) ]
421+ concat [ "%r" , to_doc ( Regex . source ( regex ) , opts ) , Regex . opts ( regex ) ]
426422 end
427423
428424 def inspect ( other , opts ) do
429- Kernel . inspect ( other , opts . raw ( true ) )
425+ to_doc ( other , opts . raw ( true ) )
430426 end
431427end
432428
0 commit comments