 
     formatted_clauses =
       if clauses do
+        format_clause_fun = fn {args, guards} ->
+          code = Enum.reduce(guards, {function, [], args}, &{:when, [], [&2, &1]})
+          "    #{kind} " <> Macro.to_string(code, ast_fun) <> "\n"
+        end
+
         top_10 =
           clauses
           |> Enum.take(10)
-          |> Enum.map(fn {args, guards} ->
-            code = Enum.reduce(guards, {function, [], args}, &{:when, [], [&2, &1]})
-            "    #{kind} " <> Macro.to_string(code, ast_fun) <> "\n"
-          end)
-
-        "\nAttempted function clauses (showing #{length(top_10)} out of #{length(clauses)}):\n\n#{top_10}"
+          |> Enum.map(format_clause_fun)
+
+        "\nAttempted function clauses (showing #{length(top_10)} out of #{length(clauses)}):" <>
+          "\n\n#{top_10}"
       else
         ""
       end

  defexception [:file, :line, description: "compile error"]

  def message(%{file: file, line: line, description: description}) do
    Exception.format_file_line(file && Path.relative_to_cwd(file), line) <>
      " " <> description
  end
end


  Note that `{:EXIT, pid}` do not generate a stacktrace though
  (as they are retrieved as messages without stacktraces).
  """
  @spec format(kind, any, stacktrace | nil) :: String.t()
  def format(kind, payload, stacktrace \\ nil)

  def format({:EXIT, _} = kind, any, _) do
