Erlang/OTP Forums

Author Message

<  Erlang  ~  Problems with my first try with Erlang

luiz.lemos
Posted: Mon Nov 17, 2008 10:38 pm Reply with quote
Joined: 17 Nov 2008 Posts: 1
Hello my friends. I tried a to mix the things that i'm learning in Erlang, but i got this message when executing the code:
** exception error: no function clause matching
amigo_secreto("Luiz","Cox")

Here's the code:

Code:

-module(amigo_secreto).
-export([sorteia/0]).

sorteia()->
   le_arquivo("nomes.txt").

le_arquivo(FileName)->
   {ok, Binary} = file:read_file(FileName),
   Lines = string:tokens(erlang:binary_to_list(Binary), "\r\n"),
   shuffle(Lines).
   
shuffle(List) -> shuffle(List, []).

shuffle([], [Head | Rest]) ->
   escolhe(Rest, Head);

shuffle(List, Acc) ->
   {Leading, [H | T]} = lists:split(random:uniform(length(List)) - 1, List),
   shuffle(Leading ++ T, [H | Acc]).
   
escolhe([Head | Rest], Escolhido)->
   tirou(Escolhido,Head),
   escolhe(Rest, Head);

escolhe([], ultimo)->
   ultimo.
   
tirou(fulano, siclano)->
   fulando,
   siclano.
   


The text file is attached.

I'd like to know how can i fix it.

Thanks
View user's profile Send private message
seanmc
Posted: Tue Nov 18, 2008 10:13 am Reply with quote
User Joined: 03 Aug 2007 Posts: 10
Hi Luiz,

You just forgot to specify the function name as well as the module name. Your call should be:

amigo_secreto:shuffle("Luiz","Cox").

//Sean.
View user's profile Send private message

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