Erlang as Functional Language
Fri May 5 15:34:37 CEST 2000
I know Thomas already answered...
> 1. In most functional languages there is a "map" function used for
> applying a certain operation on all the elements of a list.
> Like, map(*2, L) doubles all the members of list L. Is there an
> equivalent for this in Erlang? How is it used?
Here's a way involving 'map':
1> L = [1,2,3,4,5].
2> F = fun(X) -> 2*X end.
3> lists:map(F, L).
A more concise way is with a list comprehension:
4> [ 2*X || X <- [1,2,3,4,5]].
> 2. Does Erlang support lazy evaluation?
No. I think it's fairly uncontroversial to say that lazy evaluation
makes it significantly harder for humans to reason about execution
time and resource consumption, both of which tend to be important in
Hope you have fun playing with Erlang.
More information about the erlang-questions