Skip to content

Instantly share code, notes, and snippets.

@fmamud
Created October 27, 2015 18:49
Show Gist options
  • Save fmamud/b6da1af6cde0febc9adc to your computer and use it in GitHub Desktop.
Save fmamud/b6da1af6cde0febc9adc to your computer and use it in GitHub Desktop.
Erlang vamos module
-module(vamos).
-author("fmamud").
-export([foreach/2, valid_time/1, show_me_your_name/2, can_i_drink/1, oh_god/1, odd_even/1, beach/1, show_macro/2]).
-define(TIMEOUT, 20).
-define(SOMA(X, Y), X + Y).
foreach(Fun, [H|T]) ->
Fun(H),
foreach(Fun, T);
foreach(_, []) ->
ok.
show_macro(X, Y) ->
?SOMA(X, Y).
valid_time({Date = {Y,M,D}, Time = {H,Min,S}}) ->
io:format("The Date tuple (~p) says today is: ~p/~p/~p,~n",[Date,Y,M,D]),
io:format("The time tuple (~p) indicates: ~p:~p:~p.~n", [Time,H,Min,S]);
valid_time(_) ->
io:format("Stop feeding me wrong data!~n").
show_me_your_name(male, Name) ->
io:format("Hello Brow ~s, Whatsup?~n", [Name]);
show_me_your_name(female, Name) ->
io:format("Hey princess ~s, can i help you?~n", [Name]);
show_me_your_name(_, Name) ->
io:format("Hi ~s. See you later!~n", [Name]).
can_i_drink(Age) when Age >= 18 ->
you_are_a_man;
can_i_drink(Age) when Age == 11; Age =< 12 ->
you_are_a_teen;
can_i_drink(Age) when Age >= 10, Age =< 16 ->
you_are_a_boy;
can_i_drink(_) ->
you_are_a_fish.
oh_god(N) ->
if N =:= 2 -> this_is_ok;
true -> always_does
end.
odd_even(0) -> zero;
odd_even(N) ->
Number = if N rem 2 =:= 0 -> even;
N rem 2 =/= 0 -> odd;
true -> unknow
end,
{N, Number}.
beach(Temperature) ->
case Temperature of
{celsius, N} when N >= 20, N =< 45 ->
go_to_the_beach;
{fahrenheit, N} when N >= 239, N =< 318 ->
ok_you_can_go_to_the_beach;
_ -> avoid_beach
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment