Erlang as Functional Language

Matthias.Lang@REDACTED Matthias.Lang@REDACTED
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].
 [a1,2,3,4,5]
 2> F = fun(X) -> 2*X end.
 #Fun<erl_eval.19.120858100>
 3> lists:map(F, L).
 [2,4,6,8,10]

A more concise way is with a list comprehension:

  4> [ 2*X || X <- [1,2,3,4,5]].
  [2,4,6,8,10]

 > 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
telecomms applications.

Hope you have fun playing with Erlang.

Matthias



More information about the erlang-questions mailing list