[erlang-patches] Add lists:init/1 - got tired of implementing it

Fred Hebert mononcqc@REDACTED
Thu Apr 25 17:54:10 CEST 2013


Sounds to me like it would have been better implemented as something like:

init([_]) -> [];
init([H|T]) -> [H|init(T)].

As this would avoid re-building the list twice, once on each reversal.

Regards,
Fred.


On Thu, Apr 25, 2013 at 11:12 AM, Hans Svensson <hanssv@REDACTED> wrote:

> Hi,
>
> Yesterday I implemented, for the umpteenth time, the init-function. (I
> guess being taught Haskell at one point could be blamed partly for the
> coding style requiring this function...) It is a trivial function that I
> think should be part of the standard lists module. This patch adds the
> function, tests in lists_SUITE, and documentation of the function.
>
> The implementation is trivial: reverse(tl(reverse(List))).
>
> If I've missed some religious reason for not having this function feel
> free to drop the patch ;-)
>
> Cheers,
> Hans
>
> git fetch git://github.com/hanssv/otp.**git<http://github.com/hanssv/otp.git>add_init_to_lists
>
> https://github.com/hanssv/otp/**compare/erlang:maint...add_**init_to_lists<https://github.com/hanssv/otp/compare/erlang:maint...add_init_to_lists>
> https://github.com/hanssv/otp/**compare/erlang:maint...add_**
> init_to_lists.patch<https://github.com/hanssv/otp/compare/erlang:maint...add_init_to_lists.patch>
> ______________________________**_________________
> erlang-patches mailing list
> erlang-patches@REDACTED
> http://erlang.org/mailman/**listinfo/erlang-patches<http://erlang.org/mailman/listinfo/erlang-patches>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20130425/7c10fc85/attachment.htm>


More information about the erlang-patches mailing list