[erlang-questions] Beginner: What's wrong with this code?

Sid Carter sidcarter@REDACTED
Wed Jun 22 11:03:41 CEST 2011


Hi Folks,

New to Erlang and playing with code and trying to learn erlang.

I have been reading the getting started guide and trying this code (on Mac OS X with erlang from MacPorts):

-module(first).
% call would look like format_temps([{moscow,{f,-40}}, {bangalore,{f,40}}, {wellington, {c,24}}]).
-export([format_temps/1, start/0]).
format_temps([]) ->
ok;
format_temps([City|Rest]) ->
print_temp(convert_to_celsius(City)),
format_temps(Rest). 
convert_to_celsius({City, {c, C}}) ->
{City, {c, C}};
convert_to_celsius({City, {f, F}}) ->
{City, {c, (F-32)*5/9}}.
print_temp({City, {c, C}}) ->
io:format("~p has a temperature of ~w C~n",[City,C]).
start() ->
Pid = spawn(?MODULE, format_temps, [{moscow,{f,-40}}, {bangalore,{f,40}}, {wellington, {c,24}}]),
Pid.

When I try to run:

first:format_temps(args).

I don't have any problems. I get the correct response.

When I try to run as:

first:start().

I get the following error:

Error in process <0.49.0> with exit value: {undef,[{first,format_temps,[{moscow,{f,-40}},{bangalore,{f,40}},{wellington,{c,24}}]}]}

What's wrong?

Thanks
Sid



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110622/c1d432d1/attachment.htm>


More information about the erlang-questions mailing list