[erlang-questions] Question concerning the use of -export

David King dking@REDACTED
Thu Jul 12 08:46:17 CEST 2007

> My question is this: why do ping/2 and pong/0 have to be exported?

ping/2 and pong/0 have to be exported because they are called from  
within the erlang module.

erlang:spawn/3 is a BIF that ends up calling that function, and since  
it's called from outside tut15, it has to be exported. Later in that  
tutorial it mentions that you should differentiate these for  
readability, like this:

% exports for external callers

% exports for spawn

> The code is invoked from a command line by tut15:start(),
> so I can see that start/0 has to be exported. I tried not exporting
> pong/0, and got a compiler warning:
> ./tut15.erl:17: Warning: function pong/0 is unused
> I disregarded the warning and executed the code, producing a runtime
> error:
> Error in process <0.141.0> with exit value: {undef,[{tut15,pong,[]}]}
> It seems to me that pong/0 is not  being called from outside the
> tut15 module, so I should not have to export it. What am I missing  
> here?

More information about the erlang-questions mailing list