How to create a custom BIF?

Happy New Year All,

I would like to know if there is any documentation explaining how to create my own BIF (like tuple_to_list/1, etc.) for Erlang +26?

Thanks in advance

Can’t you use a NIF instead?

There isn’t, but you can check the commit history of and see if you can find an example that helps you see what is needed.


@nhpip no i can’t because I’d like to learn how BIF are made.

Well, as far as I understand it, there is no such thing as an “own BIF”, in the sense of “a natively implemented function for your application” or something. That would be a NIF. As far as I know, there is no exact definition as to what a BIF really is and what sets it apart from a NIF that just happens to “come with OTP”. But in my (personal) undestanding, one of the crucial points is that it comes with OTP, and is denoted in the

In that line, you may want to take a look at this PR. It adds a new BIF ets:give_away/2. This function is not in the erlang module, which according to some definitions does not qualify it as a “real” BIF, though.

(EDIT): And no, there is no documentation for making BIFs that I know of :woman_shrugging:


If we’re being pedantic a BIF is merely a function that is considered part of the Erlang language itself, and the name doesn’t say anything about how it’s implemented: while many are implemented in C, some are implemented in Erlang. Strictly speaking ets:give_away/2 is not a BIF even though it uses the “BIF API.”

We’ve been horribly inconsistent in naming these things though, and (often) informally call anything that uses the BIF API a “BIF” even though it’s technically a “statically linked NIF that happens to use the BIF API.”