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

Sid Carter <>
Wed Jun 22 11:13:02 CEST 2011


Thanks all, that fixed it.

Sid

On Wednesday, 22 June 2011 at 9:10 PM, Steve Strong wrote:

> Your spawn command is passing the arguments incorrectly - you need:
> 
> spawn(?MODULE, format_temps, [[{moscow,{f,-40}}, {bangalore,{f,40}}, {wellington, {c,24}}]])
> 
> without the outer list, you were trying to call first:format_temps({moscow,{f,-40}}, {bangalore,{f,40}}, {wellington, {c,24}}), which doesn't exist.
> 
> Cheers,
> 
> Steve
> --
> Steve Strong, Director, id3as
> twitter.com/srstrong (http://twitter.com/srstrong)
> 
> 
> 
> 
> On 22 Jun 2011, at 11:03, Sid Carter wrote:
> > -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.
> > 
> 
> 
> 

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


More information about the erlang-questions mailing list