Newbie compilation question

Joe Armstrong joe@REDACTED
Thu Dec 17 14:38:41 CET 1998


On Thu, 17 Dec 1998, Mark NG wrote:


> When I was writing a program I wrote "list:append/2" in my code instead of
> the correct one - "lists:append/2".  The compiler fail to notify me of that
> and when I ran it by spawning a process  it just dies out quitely...

    This  is *exactly* what it's  supposed to do. External modules are
dynamically linked into the  system at run-time.  Thus at compile time
the compiler   does  not know   anything about  what  modules  will be
available at run-time.

    The reason you don't get an error is that you use spawn. If you want an error message use spawn_link. I'll explain this in more detail:

    spawn means "spawn off a parallel process" contrast this with
    spawn_link which means "spawn off a parallel process and set a link to it,
the link means "send me an error signal if anything goes wrong".

    Let me give you a small example to illustrate the difference:

-module(ex1).

-compile(export_all).

start1() ->
    lists:append("abc", "def"),
    loop().

start2() ->
    listsmispelt:append("abc", "def"),
    loop().

loop() ->
    receive
	Any ->
	    loop()
    end.

Look what happens now:

gordons 10> erl
Erlang (JAM) emulator version 4.7.3.4
 
Eshell V4.7.3.4  (abort with ^G)
1> c(ex1).
./ex1.erl:19: Warning: function start1/0 not called
./ex1.erl:19: Warning: function start2/0 not called
{ok,ex1}
2> spawn(ex1, start1, []).
<0.34.0>
3> spawn(ex1, start2, []). 
<0.36.0>
4> spawn_link(ex1, start1, []). 
<0.38.0>
5> spawn_link(ex1, start2, []). 
<0.40.0>
** exited: {undef,{listsmispelt,append,["abc","def"]}} **

	see !

> 
> I had to use the Process Manager's tracing facility to find out that it
> is due to a missing 's' in the function call !
> 
> So, my questions is 
> 1) How can I make the compiler (I am using c:c/1) notify me of undefined 
>    symbols ?

	You can't - the compiler checks that the call is syntactically valid.

> 
> 2) How can I get the error messages of a spawn proces to appear on the shell ?
> 
	Use spawn_link instead of spawn

> 
> I am using Open Source Erlang 4.7.3 (a great language and system ;-).
> 

	Thanks

	/Joe

--
Joe Armstrong  Computer Science Laboratory  +46 8 719 9452
AT2/ETX/DN/SU  Ericsson Telecom SE-126 25 Stockholm Sweden 
joe@REDACTED    http://www.ericsson.se/cslab/~joe 








More information about the erlang-questions mailing list