Skip to content
Permalink
Browse files
use OTP_RELEASE to safely switch to lists:join/2
  • Loading branch information
bartekgorny committed Aug 30, 2018
1 parent 01c10ec commit a6cdc3a6148cc5a446b33a7e8cf33edf093b3b01
Showing 2 changed files with 25 additions and 6 deletions.
@@ -69,7 +69,7 @@ clear() ->
list() ->
F = fun({Module, Name, Fields, Limits}) ->
Fnames = lists:map(fun atom_to_list/1, Fields),
Flds = string:join(Fnames, ", "),
Flds = join(",", Fnames),
io:format("~p: #~p(~p){~s} ~p~n", [Module, Name, length(Fields), Flds, Limits])
end,
lists:foreach(F, get_list()).
@@ -194,7 +194,7 @@ format_tuple(Name, Rec) when is_atom(Name) ->
[RecDef] -> format_record(Rec, RecDef);
_ ->
List = tuple_to_list(Rec),
["{", lists:join(", ", [recon_trace:format_trace_output(true, El) || El <- List]), "}"]
["{", join(", ", [recon_trace:format_trace_output(true, El) || El <- List]), "}"]
end;
format_tuple(_, Tuple) ->
format_default(Tuple).
@@ -210,7 +210,7 @@ format_record(Rec, {{Name, Arity}, Fields, _, Limits}) ->
List = lists:zip(Fields, Values),
LimitedList = apply_limits(List, Limits),
["#", atom_to_list(Name), "{",
lists:join(", ", [format_kv(Key, Val) || {Key, Val} <- LimitedList]),
join(", ", [format_kv(Key, Val) || {Key, Val} <- LimitedList]),
"}"];
_ ->
format_default(Rec)
@@ -249,3 +249,12 @@ wait_for_death(Pid, Name) ->
ok
end.

-ifdef(OTP_RELEASE).
-spec join(term(), [term()]) -> [term()].
join(Sep, List) ->
lists:join(Sep, List).
-else.
-spec join(string(), [string()]) -> string().
join(Sep, List) ->
string:join(List, Sep).
-endif.
@@ -601,7 +601,7 @@ format_args(Arity) when is_integer(Arity) ->
["/", integer_to_list(Arity)];
format_args(Args) when is_list(Args) ->
Active = recon_rec:is_active(),
["(", lists:join(", ", [format_trace_output(Active, Arg) || Arg <- Args]), ")"].
["(", join(", ", [format_trace_output(Active, Arg) || Arg <- Args]), ")"].


%% @doc formats call arguments and return values - most types are just printed out, except for
@@ -617,12 +617,12 @@ format_trace_output(true, Args) when is_list(Args) ->
true -> io_lib:format("~p", [Args]);
false ->
L = lists:map(fun(A) -> format_trace_output(true, A) end, Args),
"[" ++ string:join(L, ", ") ++ "]"
"[" ++ join(", ", L) ++ "]"
end;
format_trace_output(true, Args) when is_map(Args) ->
ItemList = maps:to_list(Args),
["#{",
lists:join(", ", [format_kv(Key, Val) || {Key, Val} <- ItemList]),
join(", ", [format_kv(Key, Val) || {Key, Val} <- ItemList]),
"}"];
format_trace_output(_, Args) ->
io_lib:format("~p", [Args]).
@@ -669,3 +669,13 @@ fun_to_ms(ShellFun) when is_function(ShellFun) ->
false ->
exit(shell_funs_only)
end.

-ifdef(OTP_RELEASE).
-spec join(term(), [term()]) -> [term()].
join(Sep, List) ->
lists:join(Sep, List).
-else.
-spec join(string(), [string()]) -> string().
join(Sep, List) ->
string:join(List, Sep).
-endif.

0 comments on commit a6cdc3a

Please sign in to comment.