Code · 1 file

Sample Erlang File

Erlang is the language of telecom switches and WhatsApp, built for concurrency and fault tolerance. The Erlang sample is a small program — a customer record, a VIP check and a formatted total — that is the same in every language we offer, so you can compare them side by side.

Erlang · 719 B

Sample Erlang file

An idiomatic Erlang example: a customer record type, a VIP check, a total and a formatted loop — the same program in every language we offer.

CC0 · free for any use · Verified by an independent tool · Report a problem

sample.erl — first linesErlang
%% Sample Erlang module — samplefiles.com
-module(sample).
-export([main/0, is_vip/1, total_balance/1]).

-record(customer, {id, name, balance}).

is_vip(#customer{balance = B}) -> B >= 10000.

total_balance(Customers) -> lists:sum([C#customer.balance || C <- Customers]).

main() ->
    Customers = [#customer{id = 1, name = "Ada", balance = 12500.0},
                 #customer{id = 2, name = "Grace", balance = 830.5},
                 #customer{id = 3, name = "Linus", balance = 10000.0}],
    [io:format("~-6s ~10.2f ~s~n", [C#customer.name, C#customer.balance, vip(C)]) || C <- Customers],
    io:format("Total: ~.2f~n", [total_balance(Customers)]).

vip(C) -> case is_vip(C) of true -> "VIP"; false -> "" end.

File details

Size
719 B (719 bytes)
MIME type
text/plain
SHA-256
ba513b51a070aff46f08414299a43f796a203234ce3679d7ed2b617d185295a0
MD5
6752511bc94241343814fefde582b99a

Download from the command line

curl -L -o sample.erl https://files.samplefiles.com/code/erl/sample.erl

Or check the download in your browser with the checksum calculator.