Skip to content

Instantly share code, notes, and snippets.

@mrnovalles
Created October 16, 2011 17:54
Show Gist options
  • Save mrnovalles/1291190 to your computer and use it in GitHub Desktop.
Save mrnovalles/1291190 to your computer and use it in GitHub Desktop.
Getting to know who peer reviews a Sci-Writing assignment
-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.
@nruth
Copy link

nruth commented Oct 16, 2011

Por ¿ qué

@mrnovalles
Copy link
Author

mrnovalles commented Oct 16, 2011 via email

@archie
Copy link

archie commented Oct 17, 2011

Hm... Usted está loco! As an improvement though, may I suggest you remove the if-clauses and use pattern matching instead ;)

@mrnovalles
Copy link
Author

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?

@nruth
Copy link

nruth commented Oct 18, 2011

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.

@archie
Copy link

archie commented Nov 1, 2011

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'.

@nruth
Copy link

nruth commented Nov 1, 2011

What about using eval:

-module(peer).
-export ([draw/0]).

draw() -> os:cmd("ruby -e 'print %w(Vasia Lalith Mariano).choice'").

@archie
Copy link

archie commented Nov 2, 2011

Hahah! That's avoiding the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment