Skip to content

Instantly share code, notes, and snippets.

@arunthampi
Created September 1, 2008 16:28
Show Gist options
  • Save arunthampi/8319 to your computer and use it in GitHub Desktop.
Save arunthampi/8319 to your computer and use it in GitHub Desktop.
% Example of Erlang guards
-module(double).
-export([double/1]).
%% If guard expressions are separated by a comma, it means AND.
%% If guard expressions are separated by a semi-colon, it means OR.
double(X) when X > 0; X < 0 -> X * 2;
% If a function has multiple lines, each line (except the last), must be
% terminated by a comma
double(X) when X =:= 0 -> io:format("Trying to double a zero homie?~n"),
0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment