[erlang-questions] Bound(?) var in anonymous fun
Pablo Vieytes
pablo.vb80@REDACTED
Tue Dec 18 13:01:27 CET 2012
I have to get used to use list comprehension. I know how it works but I
never remember use it.
2012/12/18 Loïc Hoguin <essen@REDACTED>
> This one only removes the first element. :)
>
>
> On 12/18/2012 12:34 PM, Max Bourinov wrote:
>
>> Or even more shooter:
>>
>> lists:delete(Key, StatusList).
>>
>>
>> On Tue, Dec 18, 2012 at 3:22 PM, Dmitry Klionsky <dm.klionsky@REDACTED
>> <mailto:dm.klionsky@REDACTED>**> wrote:
>>
>> On 12/18/2012 02:08 PM, Manuel A. Rubio "Bombadil" wrote:
>>
>> Hi Pablo,
>>
>> El 2012-12-18 11:54, Pablo Vieytes escribió:
>>
>> I guessed Key was bound so I could use for pattern matching.
>> It's
>> very easy to fix it but I don't know why it doesn't work.
>>
>>
>> This doesn't works well because the params are not inside of
>> binding in closures. The params are the interface with the
>> outside world and will be confuse know if a param is a binding
>> or not. By default Erlang hasn't binding in function params.
>>
>> Fixed version:
>>
>> delete_key_from_list(Key, StatusList)->
>> lists:foldr(
>> fun(K, Acc) when K == Key ->
>> Acc;
>> (Another, Acc) ->
>> [Another|Acc]
>> end,
>> [],
>> StatusList).
>>
>>
>> This code could be writted as:
>>
>> delete_key_from_list(Key, StatusList)->
>> lists:filter(fun(X) -> Key =/= X end, StatusList).
>>
>> Regards,
>> Manuel Rubio.
>> ______________________________**___________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED <mailto:erlang-questions@**erlang.org<erlang-questions@REDACTED>
>> >
>> http://erlang.org/mailman/__**listinfo/erlang-questions<http://erlang.org/mailman/__listinfo/erlang-questions>
>>
>> <http://erlang.org/mailman/**listinfo/erlang-questions<http://erlang.org/mailman/listinfo/erlang-questions>
>> >
>>
>>
>> Or even more readable as:
>>
>> delete_key_from_list(Key, StatusList)->
>> [Status || Status <- StatusList, Status =/= Key].
>>
>> --
>> Best regards,
>> Dmitry Klionsky
>>
>>
>> ______________________________**___________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED <mailto:erlang-questions@**erlang.org<erlang-questions@REDACTED>
>> >
>> http://erlang.org/mailman/__**listinfo/erlang-questions<http://erlang.org/mailman/__listinfo/erlang-questions>
>> <http://erlang.org/mailman/**listinfo/erlang-questions<http://erlang.org/mailman/listinfo/erlang-questions>
>> >
>>
>>
>>
>>
>>
>> ______________________________**_________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/**listinfo/erlang-questions<http://erlang.org/mailman/listinfo/erlang-questions>
>>
>>
>
> --
> Loïc Hoguin
> Erlang Cowboy
> Nine Nines
> http://ninenines.eu
>
> ______________________________**_________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/**listinfo/erlang-questions<http://erlang.org/mailman/listinfo/erlang-questions>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20121218/cad4d1d0/attachment.htm>
More information about the erlang-questions
mailing list