Why is lists:zf/2 an alias for filtermap/2 in Erlang?
It's an undocumented but exported function in the lists: module. Here is the implementation:
zf(F, L) ->
filtermap(F, L).
What I'm baffled by is:
In Erlang, Lists are created by enclosing the values in square brackets. Following is a simple example of creating a list of numbers in Erlang.
You can use length() to find the length of a list, and can use list comprehensions to filter your list. num(L) -> length([X || X <- L, X < 1]).
As Robert Virding, a co-inventor of Erlang, wrote in 2016:
The lists:zf/2 function came before list comprehensions and is a combination of map and filter. Like describing a set from a set of rules. Hence the Zermelo-Fraenkel based name. It is also called lists:filtermap/2 but where’s the fun in that?
So, your guess is absolutely correct.
My old answer is perfectly correct, it does stand for Zermelo-Fraenkel. The name was chosen to be a bit of a joke. We could do that in those days.
It is similar to why we use 'reductions' in process info as a measure of how much work a process has done, basically the number of function calls. Originally, way back when, Erlang was implemented in Prolog and there they had reductions not function calls and we decided to keep it as a bit of a joke. Any suggestions that it has something to do with the theory of functional languages have got it wrong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With