Created
October 16, 2011 17:54
-
-
Save mrnovalles/1291190 to your computer and use it in GitHub Desktop.
Getting to know who peer reviews a Sci-Writing assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(peer). | |
-export ([draw/0]). | |
draw()-> | |
R = random:uniform(100), | |
io:format ("~w",[r]), | |
if | |
R < 33 -> | |
io:format ("Vasia peer reviews Erisa's S. Writing"); | |
true -> | |
if | |
R < 66 -> | |
io:format ("Lalith peer reviews Erisa's S. Writing"); | |
true -> | |
io:format ("Mariano peer reviews Erisa's S. Writing") | |
end | |
end. |
Para recordar un poco Erlang !
…On Mon, Oct 17, 2011 at 1:10 AM, Nicholas Rutherford ***@***.*** wrote:
Por ¿ qué
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1291190
Hm... Usted está loco! As an improvement though, may I suggest you remove the if-clauses and use pattern matching instead ;)
how could you pattern match with conditions? wow, I have really lost my Erlang.
Let's say now there are only two possibilities to make it simple , I could do:
draw() ->
R = random:uniform(100),
if
R < 50 ->
test ! {smallerThan33, R} ,
true ->
test ! {biggerThan33, R}
end
And do the pattern matching and printouts in the test function.
What other way do you propose?
I'd suggest case/switch, since that allows simple predicate tests which you can't put in function definitions, but it'll look quite similar.
One way could be:
-module(peer).
-export ([draw/0]).
draw()->
R = random:uniform(100),
io:format ("~p peer reviews Erisa's S. Writing~n", [draw(R)]).
draw(R) when R < 33 ->
'Vasia';
draw(R) when R < 66 ->
'Lalith';
draw(_R) ->
'Mariano'.
What about using eval:
-module(peer).
-export ([draw/0]).
draw() -> os:cmd("ruby -e 'print %w(Vasia Lalith Mariano).choice'").
Hahah! That's avoiding the problem.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Por ¿ qué