Erlang – droplast

Erlang droplast

In this guide, we will discuss Erlang droplast. Drops the last element of a List. The list should be non-empty, otherwise the function will crash with a function_clause.

Syntax

droplast(List1)

Parameters

  • List1 − The list of values.

Return Value

Returns a new list with the last element deleted.

For example

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

start() -> 
   Lst1 = [1,2,3], 
   Lst2 = droplast(Lst1), 
   io:fwrite("~w~n",[Lst2]).

Output

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

[1,2]

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply