An example of how the Tuple data type can be used is shown in the following program.
Here we are defining a Tuple P which has 3 terms. The tuple_size is an inbuilt function defined in Erlang which can be used to determine the size of the Tuple.
Example
-module(helloworld). -export([start/0]). start() -> P = {john,24,{june,25}} , io:fwrite("~w",[tuple_size(P)]).The output of the above program will be as follows.
Output
3Let’s look at some more operations which are available for tuples.
| S.No | Methods & Description |
|---|---|
| 1 |
is_tuple
This method is used to determine is the term provided is indeed a tuple. |
| 2 |
list_to_tuple
This method is to convert a list to a tuple. |
| 3 | tuple_to_list This method is convert a tuple to a list. |
No comments:
Post a Comment