Erlang - sum


Advertisements


Returns the sum of elements in the list.

Syntax

sum(lst)

Parameters

  • Lst − The list of elements.

Return Value

Returns the sum of elements in the list.

For example

Live Demo
-module(helloworld). 
-import(lists,[sum/1]). 
-export([start/0]). 

start() -> 
   Lst1 = [5,6,4], 
   io:fwrite("~p~n",[sum(Lst1)]).

Output

When we run the above program, we will get the following result.

15

erlang_lists.htm

Advertisements