From 3fba785183210dd935a99632a653302e6f832ba4 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Wed, 10 Aug 2022 08:58:21 +0100 Subject: Use different syntax for improper lists --- src/gleam_stdlib.erl | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl index 9fc1c4a..b2aa135 100644 --- a/src/gleam_stdlib.erl +++ b/src/gleam_stdlib.erl @@ -348,9 +348,8 @@ inspect(Binary) when is_binary(Binary) -> Segments = [erlang:integer_to_list(X) || <> <= Binary], ["<<", lists:join(", ", Segments), ">>"] end; -inspect(List) when is_list(List) -> - Elements = lists:join(<<", ">>, do_map_listish(fun inspect/1, List)), - ["[", Elements, "]"]; +inspect(Elements) when is_list(Elements) -> + ["[", inspect_list(Elements), "]"]; inspect(Any) when is_tuple(Any) % Record constructors andalso is_atom(element(1, Any)) andalso element(1, Any) =/= false @@ -375,13 +374,15 @@ inspect(Any) when is_function(Any) -> inspect(Any) -> ["//erl(", io_lib:format("~p", [Any]), ")"]. -do_map_listish(_Fn, []) -> + +inspect_list([]) -> []; -do_map_listish(Fn, List) when is_list(List) -> - [Head | Tail] = List, - [Fn(Head) | do_map_listish(Fn, Tail)]; -do_map_listish(Fn, Tail) when not is_list(Tail) -> - [Fn(Tail)]. +inspect_list([Head]) -> + [inspect(Head)]; +inspect_list([First | Rest]) -> + [inspect(First), <<", ">> | inspect_list(Rest)]; +inspect_list(ImproperTail) -> + [<<"...">>, inspect(ImproperTail)]. float_to_string(Float) when is_float(Float) -> erlang:iolist_to_binary(io_lib_format:fwrite_g(Float)). -- cgit v1.2.3