📜  Erlang-BIFS

📅  最后修改于: 2020-11-04 05:57:09             🧑  作者: Mango


BIF是Erlang中内置的函数。他们通常执行无法在Erlang中编程的任务。例如,不可能将列表变成元组或找到当前时间和日期。为了执行这样的操作,我们称为BIF。

让我们举一个如何使用BIF的例子-

-module(helloworld). 
-export([start/0]). 

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

关于上述示例,需要注意以下几点:

  • 在第一个示例中,我们使用称为tuple_to_list的BIF将元组转换为列表。

  • 在第二个BIF函数,我们使用时间函数来输出系统时间。

上面程序的输出如下:

输出

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

让我们看一下Erlang中可用的更多BIF函数。

Sr.No. BIF Functions & Description
1

date

This method returns the current system date.

2

byte_size

This method returns the number of bytes contained in a Bitstring.

3

element

The method returns the Nth element in the tuple.

4

float

This method returns the float value of a particular number.

5

get

The method returns the process dictionary as a list.

6

put

This method is used to put a key,value pair in the process dictionary.

7

localtime

The method is used to give the local date and time in the system.

8

memory

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

9

now

This method returns the tuple {MegaSecs, Secs, MicroSecs} which is the elapsed time since 00:00 GMT, January 1, 1970.

10

ports

Returns a list of all ports on the local node

11

processes

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

12

universaltime

Returns the current date and time according to Universal Time Coordinated (UTC).