File 1428-Make-specs-for-hd-1-and-tl-1-more-specific.patch of Package erlang

From 90bd9daaa4caa2906b62c921e479209dc6d082c3 Mon Sep 17 00:00:00 2001
From: Eksperimental <eksperimental@autistici.org>
Date: Tue, 31 May 2022 11:08:51 -0500
Subject: [PATCH] Make specs for hd/1 and tl/1 more specific

This also stream lines with the development of the analogous functions in Elixir:

- https://github.com/elixir-lang/elixir/blob/01361af9fe582c71abdb9746c854f6fe59fbf511/lib/elixir/lib/kernel.ex#L550
- https://github.com/elixir-lang/elixir/blob/01361af9fe582c71abdb9746c854f6fe59fbf511/lib/elixir/lib/kernel.ex#L1249-L1250
---
 erts/doc/src/erlang.xml       | 15 +++++++++++----
 erts/preloaded/src/erlang.erl | 10 ++++++----
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/erts/doc/src/erlang.xml b/erts/doc/src/erlang.xml
index ee5b08cacc..7085440e1f 100644
--- a/erts/doc/src/erlang.xml
+++ b/erts/doc/src/erlang.xml
@@ -2994,12 +2994,17 @@ os_prompt%</pre>
       <fsummary>Head of a list.</fsummary>
       <desc>
         <p>Returns the head of <c><anno>List</anno></c>, that is,
-          the first element, for example:</p>
+          the first element.</p>
+        <p>It works with improper lists.</p>
+        <p>Examples:</p>
         <pre>
 > <input>hd([1,2,3,4,5]).</input>
 1</pre>
+        <pre>
+> <input>hd([first, second, third, so_on | improper_end]).</input>
+first</pre>
         <p>Allowed in guard tests.</p>
-        <p>Failure: <c>badarg</c> if <c><anno>List</anno></c> is the empty
+        <p>Failure: <c>badarg</c> if <c><anno>List</anno></c> is an empty
           list <c>[]</c>.</p>
       </desc>
     </func>
@@ -11853,7 +11858,9 @@ timestamp() ->
       <fsummary>Tail of a list.</fsummary>
       <desc>
         <p>Returns the tail of <c><anno>List</anno></c>, that is,
-          the list minus the first element, for example:</p>
+          the list minus the first element</p>
+        <p>It works with improper lists.</p>
+        <p>Examples:</p>
         <pre>
 > <input>tl([geesties, guilies, beasties]).</input>
 [guilies, beasties]</pre>
@@ -11868,7 +11875,7 @@ timestamp() ->
 improper_end</pre>
         <p>Allowed in guard tests.</p>
         <p>Failure: <c>badarg</c> if <c><anno>List</anno></c>
-          is the empty list <c>[]</c>.</p>
+          is an empty list <c>[]</c>.</p>
       </desc>
     </func>
 
diff --git a/erts/preloaded/src/erlang.erl b/erts/preloaded/src/erlang.erl
index 470f861e08..8afcfd37ad 100644
--- a/erts/preloaded/src/erlang.erl
+++ b/erts/preloaded/src/erlang.erl
@@ -2197,8 +2197,9 @@ get_module_info(_Module, _Item) ->
     erlang:nif_error(undefined).
 
 %% Shadowed by erl_bif_types: erlang:hd/1
--spec hd(List) -> term() when
-      List :: [term(), ...].
+-spec hd(List) -> Head when
+      List :: nonempty_maybe_improper_list(),
+      Head :: term().
 hd(_List) ->
     erlang:nif_error(undefined).
 
@@ -2774,8 +2775,9 @@ term_to_iovec(_Term, _Options) ->
     erlang:nif_error(undefined).
 
 %% Shadowed by erl_bif_types: erlang:tl/1
--spec tl(List) -> term() when
-      List :: nonempty_maybe_improper_list().
+-spec tl(List) -> Tail when
+      List :: nonempty_maybe_improper_list(),
+      Tail :: term().
 tl(_List) ->
     erlang:nif_error(undefined).
 
-- 
2.35.3

openSUSE Build Service is sponsored by