[erlang-questions] Erlang/OTP 21.0-rc1 (Release Candidate)

Lukas Larsson lukas@REDACTED
Wed May 2 21:22:57 CEST 2018


The argument order in the email is a typo, which is what Dmitry tried to
point out.

http://erlang.org/documentation/doc-10.0-rc1/lib/stdlib-3.5/doc/html/lists.html#search-2

It is lists:search(Pred, List).

On Wed, 2 May 2018, 21:12 Alexander Petrovsky, <askjuise@REDACTED> wrote:

> Totally agree with Frans Schneider, the arguments order in different
> modules in stdlib differs from one to another. And I think will be better
> reorder args in lists:search.
>
> For me much more close approach suggested by Chris Okasaki, short summary
> from SO (
> https://stackoverflow.com/questions/5863128/ordering-of-parameters-to-make-use-of-currying
> ):
>
> For languages that support currying and partial-application easily, there
>> is one compelling series of arguments, originally from Chris Okasaki:
>>
>>    - *Put the data structure as the last argument*
>>
>> Why? You can then compose operations on the data
>> <http://www.haskell.org/pipermail/libraries/2005-August/004297.html> nicely.
>> E.g. insert 1 $ insert 2 $ insert 3 $ s. This also helps for functions
>> on state
>> <http://www.haskell.org/pipermail/libraries/2005-August/004323.html>.
>> Standard libraries such as "containers" follow this convention
>> <http://hackage.haskell.org/packages/archive/containers/0.4.0.0/doc/html/Data-Map.html#g:5>
>> .
>> Alternate arguments are sometimes given to put the data structure first,
>> so it can be closed over, yielding functions on a static structure (e.g.
>> lookup) that are a bit more concise. However, the broad consensus seems to
>> be that this is less of a win, especially since it pushes you towards
>> heavily parenthesized code.
>>
>>    - *Put the most varying argument last*
>>
>> For recursive functions, it is common to put the argument that varies the
>> most (e.g. an accumulator) as the last argument, while the argument that
>> varies the least (e.g. a function argument) at the start. This composes
>> well with the data structure last style.
>
>
> So, the
>
> lists:search(fun/1, list) -> {ok, Value} | false
>
>
>  will be more appropriate then
>
> lists:search(list, fun/1) -> {ok, Value} | false
>
>
>
>>
> ср, 2 мая 2018 г. в 16:10, Dmitry Klionsky <dm.klionsky@REDACTED>:
>
>> No, it's fine.
>>
>>
>> https://github.com/erlang/otp/blob/master/lib/stdlib/src/lists.erl#L1402-L1413
>>
>>
>> On 05/02/2018 04:06 PM, Frans Schneider wrote:
>> > Is the fun/1 really the second argument in the call lists:search/2?
>> >
>> > lists:search(list,fun/1) -> {ok, Value} | false
>> >
>> > Doesn't feel consistent with the other functions in the list module
>> > which have the fun/1 as the first argument.
>> >
>> > Cheers,
>> >
>> > Frans
>> >
>> > On 05/02/2018 01:37 PM, Henrik Nord X wrote:
>> >> lists:search(list,fun/1) -> {ok, Value} | false
>> > _______________________________________________
>> > erlang-questions mailing list
>> > erlang-questions@REDACTED
>> > http://erlang.org/mailman/listinfo/erlang-questions
>>
>> --
>> BR,
>> Dmitry
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180502/b59ac7a8/attachment.htm>


More information about the erlang-questions mailing list