Reputation: 31
I want to implement an Erlang interpreter and recently I'm reading about Erlang's standard library source code. I find the source code of erlang:display/1 in erlang.erl is:
%% display/1
-spec erlang:display(Term) -> true when
Term :: term().
display(_Term) ->
erlang:bif_error(undefined).
I don't know how it works to make a display behavior, and I think it simply throw a undefined error anyway. By the way I've also hacked the erlang.beam to make sure the bytecode has the same semantics as the source code (erlang.erl) do. Could anyone tell me how the erlang:display actually do?
Upvotes: 3
Views: 830
Reputation: 13220
erlang:display/1
is a BIF (built-in function). Some BIFs are implemented in Erlang, but most of them are implemented as primitive operations in the Erlang virtual machine since BIFs provide interfaces to the operating system or perform operations that are impossible or very inefficient to program in Erlang.
You might want to have a look to A GUIDE TO THE ERLANG SOURCE, briefly, it says;
The BIFs are summed up in the bif.tab file. For example:
Line 54: bif erlang:display/1
means the display/1
BIF is mapped to the display_1
method in the bif.c file.
Upvotes: 5