Erlang/OTP Forums

Author Message

<  Erlang questions mailing list  ~  Newbie compilation question

markn at students.cs.mu.O
Posted: Thu Dec 17, 1998 10:51 am Reply with quote
Guest
Hallo !


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...

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 ?

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


I am using Open Source Erlang 4.7.3 (a great language and system Wink.

any help would be appreciated,
thanks !
mark


Post generated using Mail2Forum (http://m2f.sourceforge.net)
joe at erix.ericsson.se
Posted: Thu Dec 17, 1998 1:39 pm Reply with quote
Guest
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 Wink.
>

Thanks

/Joe

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







Post generated using Mail2Forum (http://m2f.sourceforge.net)
joe at erix.ericsson.se
Posted: Fri Dec 18, 1998 7:20 am Reply with quote
Guest
Something that I forgot in my last reply was that there is an
infix operator "++" which can be used instead of append/2, so, for
example, the expressions:

File = lists:append(Name, ".erl") you
and File = Name ++ ".erl",

are equivalent.

/Joe



Post generated using Mail2Forum (http://m2f.sourceforge.net)
bjarne at erix.ericsson.s
Posted: Fri Dec 18, 1998 9:03 am Reply with quote
Guest
Hello,

Joe Armstrong wrote:

> Something that I forgot in my last reply was that there is an
> infix operator "++" which can be used instead of append/2

What fun. I had only thought of using ++ in
connection with strings and immediately tried

1> [1,2,3] ++ [4,5,6].

[1,2,3,4,5,6]

Rgrds,

Bjarne





Post generated using Mail2Forum (http://m2f.sourceforge.net)
klacke at erix.ericsson.s
Posted: Fri Dec 18, 1998 9:57 am Reply with quote
Guest
Mark NG writes:
>
>
> Hallo !
>
>
> 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...
>
> 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 ?

This we simply cannot do. All references to modules and functions are
resolved at runtime. There is no link phase at all !!!
This is so since we want to be able to load code in the running system
in a flexible way.

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

This can be done, but it's not easy. This is what happens:

1. The runtime system creates an new process.
2. The process start to execute.
3. The runtime system sees a call to list:append/2 (miss spelled)
4. The runtime system realizes that no module named 'list' is loaded
so insted it invokes nother module called the error_handler

Thus the call to list:append(X,Y) is transformd into a call
error_handler:undefined_function(list, append, [X, Y])

This error_handler module resides in kernel/src/error_handler.erl

The error_handler (in kernel/src) will ask the code server to
search the load_path and try to load a module called list.jam

If this failes, the error_hanler simply does a call to
exit({undef,{Module,Func,Args}})

Which will silently exit te process.

However in an environment where we sit and develop we could
sometimes want to have a different behaviour there, for example
print a little friendly something on stdout saying that we can't find
the module list.erl
This is bad default behaviour though.

As an exercise you could try to modify the error_handler to do
just that and then (maybe in your ~/.erlang) load your own
error_handler instead of the systems.

I know that Arndt Jonason has done just that, he is running
some weird error_handler that tries to correct misspelleded
modules at runtime !!

You can also give the -pa Dir flag to 'erl' and point it
to a directory where a different error_handler resides.

Cheers

/klacke



Post generated using Mail2Forum (http://m2f.sourceforge.net)

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum