Erlang (programming language)/Tutorials/Lists: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>Eric Evers
imported>Eric Evers
Line 2: Line 2:


=Lists Module=
=Lists Module=
==Math==
math:asin(1).
  3.1415
sqrt(4).
  2


==Map==
==Map==
  6> Sqrt = fun(X) -> math:sqrt(X) end.
  6> Sqrt = fun(X) -> math:sqrt(X) end.
  #Fun<erl_eval.6.56006484>
  #Fun<erl_eval.6.56006484>
Line 12: Line 17:


==Sort==
==Sort==
  lists:sort([2,4,3,5]).
  lists:sort([2,4,3,5]).
  [2,3,4,5]
  [2,3,4,5]

Revision as of 12:59, 5 May 2008


Lists Module

Math

math:asin(1).
 3.1415
sqrt(4).
 2

Map

6> Sqrt = fun(X) -> math:sqrt(X) end.
#Fun<erl_eval.6.56006484>
7> lists:map(Sqrt,[1,2,3,4]).
[1.00000,1.41421,1.73205,2.00000]

Sort

lists:sort([2,4,3,5]).
[2,3,4,5]