diff options
author | Louis Pilfold <louis@lpil.uk> | 2022-08-10 08:58:21 +0100 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-08-10 08:58:21 +0100 |
commit | 3fba785183210dd935a99632a653302e6f832ba4 (patch) | |
tree | af69fffb72709f87b9fbc4909867432db56f283d /src/gleam_stdlib.erl | |
parent | 95425ffdc5407e9ec60efed9b8d4fa7c1fdfb764 (diff) | |
download | gleam_stdlib-3fba785183210dd935a99632a653302e6f832ba4.tar.gz gleam_stdlib-3fba785183210dd935a99632a653302e6f832ba4.zip |
Use different syntax for improper lists
Diffstat (limited to 'src/gleam_stdlib.erl')
-rw-r--r-- | src/gleam_stdlib.erl | 19 |
1 files changed, 10 insertions, 9 deletions
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) || <<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)). |