|
|
| Author |
Message |
< Erlang ~ Problems with my first try with Erlang |
| luiz.lemos |
Posted: Mon Nov 17, 2008 10:38 pm |
|
|
|
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 |
|
|
| Back to top |
|
| seanmc |
Posted: Tue Nov 18, 2008 10:13 am |
|
|
|
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. |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
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
|
|
|