English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

BIFs (Built-In Functions) in Erlang

BIFs are built-in functions in Erlang. They usually perform tasks that cannot be programmed in Erlang. For example, it is impossible to convert a list to a tuple, and it is also impossible to find the current date and time. To perform such operations, we call them BIFs.

Let's take an example of how to use BIFs-

Online Example

-module(helloworld). 
-export([start/0]). 
start() ->   
   io:fwrite("~p~n",[tuple_to_list({1,2,3})]), 
   io:fwrite("~p~n",[time()]).

For the above examples, the following points should be noted:

  • In the first example, we use the BIF named tuple_to_list to convert a tuple to a list.

  • In the second BIF function, we usetime functionTo output the system time.

The output of the above program is as follows:

[1,2,3]
{10,54,56}

Let's take a look at more available BIF functions in Erlang.

Serial NumberBIF Functions and Descriptions
1

date

This method returns the current system date.

2

byte_size

This method returns the number of bytes contained in a bit string.

3

element

This method returns the Nth element of the tuple.

4

float

This method returns the floating-point value of a specific number.

5

get

This method returns the process dictionary as a list.

6

put

This method is used forkey,valuePlace a key-value pair in the process dictionary.

7

localtime

This method is used to provide the local date and time in the system.

8

memory

Returns a list containing information about the memory dynamically allocated by the Erlang simulator.

9

now

This method returns the tuple {MegaSecs, Secs, MicroSecs}, which is the time1970 years1Month1Time elapsed since 00:00:00 GMT.

10

ports

Returns a list of all ports on the local node

11

processes

Returns a list of process identifiers corresponding to all processes currently existing on the local node.

12

universaltime

Returns the current date and time based on Coordinated Universal Time (UTC).