Upload
prasv
View
254
Download
6
Embed Size (px)
Citation preview
8/8/2019 Erlang - Cheatsheet v1.0
1/1
ERLANG CHEAT SHEET V1.0Marouan OMEZZINE(marouan.omezzine[~at~]gmail[~dot~]com) http://www.myownpercept.com/2009/03/erlang-cheat-sheet/SAMPLE MODULEmodule(foo).
export([sayhi/0]).
% This is a comment.
sayhi() ->
o:format("Happy Erlanging!~n" ).
GETTING HELPerl -man
CASE EXPRESSIONScase Expression of
Pattern1 [when Guard1] -> Expr_seq1;Pattern2 [when Guard2] -> Expr_seq2;...
end
F EXPRESSIONSf
Guard1 ->Expr_seq1;
Guard2 ->Expr_seq2;
...end
TERM COMPARISONSX> Y X is greater than Y.X< Y X is less than Y.X=< Y X is equal to or less than Y.X>= Y X is greater than or equal to Y.X== Y X is equal to Y.X/= Y X is not equal to Y.X=:= Y X is identical to Y.X=/= Y X is not identical to Y.
OIo:format( I am ~s~n, [String]).Io:fwrite(I am ~s~n, [String]).~n : new line | ~s: string |~f=> float |~w:standard output |~p: like ~w but breaks after eachline
LISTListA = [1,2,3,4].Returns [1,2,3,4]
ListB = [1+7,hello,2-2,{cost, apple, 30-20},3].Returns [8,hello,0,{cost,apple,10},3]
[H|T] = ListA.Returns the Head and Tail.
Comprehensions
L = [ X*X || X X*X end, [1,2,3])
This gives the output: [1,4,9]Simple Comprehensions
L = [ {X,Y} || X