Sunday, May 4, 2014

Erlang Tuple functions

-module(tuple_functions).
-export([start/1]).

start(Tuple) ->
    select_element_by_index(Tuple),
    set_element(Tuple),
    find_tuple_size(Tuple),
    pass_tuple_values_to_variables(Tuple).
  
select_element_by_index(Tuple) ->
    io:format("2 nd element of the Tuple ..... ~p~n",[element(2,Tuple)]).  % element(index of the required value,input tuple)

set_element(Tuple) ->
    io:format("Replaces the old element in 2nd place with 45 in the tuple .... ~p~n",[setelement(2,Tuple,45)]). % setelement(index of the old value, input tuple, new value)

find_tuple_size(Tuple) ->
    io:format("Size of the tuple .... ~p~n",[tuple_size(Tuple)]). % tuple_size(input tuple)

pass_tuple_values_to_variables({Var1, Var2, Var3, Var4}) ->
    io:format("1 st position value of the tuple ..... ~p~n",[Var1]),
    io:format("2 st position value of the tuple ..... ~p~n",[Var2]),
    io:format("3 st position value of the tuple ..... ~p~n",[Var3]),
    io:format("4 st position value of the tuple ..... ~p~n",[Var4]).

Labels: , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home